generated from kse-ua/quick-start
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
438 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
rm(list = ls(all.names = TRUE)) # Clear the memory of variables from previous run. This is not called by knitr, because it's above the first chunk. | ||
cat("\014") # Clear the console | ||
# verify root location | ||
cat("Working directory: ", getwd()) # Must be set to Project Directory | ||
# Project Directory should be the root by default unless overwritten | ||
|
||
# ---- load-packages ----------------------------------------------------------- | ||
# Choose to be greedy: load only what's needed | ||
# Three ways, from least (1) to most(3) greedy: | ||
# -- 1.Attach these packages so their functions don't need to be qualified: http://r-pkgs.had.co.nz/namespace.html#search-path | ||
library(ggplot2) # graphs | ||
library(forcats) # factors | ||
library(stringr) # strings, but consider `stringi` as more general | ||
library(lubridate) # dates | ||
library(labelled) # labels | ||
library(dplyr) # data wrangling | ||
# -- 2.Import only certain functions of a package into the search path. | ||
import::from("magrittr", "%>%") | ||
# -- 3. Verify these packages are available on the machine, but their functions need to be qualified: http://r-pkgs.had.co.nz/namespace.html#search-path | ||
requireNamespace("readr" )# data import/export | ||
requireNamespace("readxl" )# data import/export | ||
requireNamespace("tidyr" )# tidy data | ||
requireNamespace("janitor" )# tidy data | ||
requireNamespace("testit" )# for asserting conditions meet expected patterns. | ||
requireNamespace("scales" )# formatting | ||
|
||
# ---- load-sources ------------------------------------------------------------ | ||
base::source("./scripts/common-functions.R") # project-level | ||
|
||
# ---- declare-globals --------------------------------------------------------- | ||
Sys.setlocale("LC_CTYPE", "ukr") | ||
# printed figures will go here when `quick_save("name",w=8,h=6)` is used: | ||
prints_folder <- paste0("./analysis/ua-pop-2022/prints/") | ||
if (!fs::dir_exists(prints_folder)) { fs::dir_create(prints_folder) } | ||
|
||
path_data_input <- "./data-private/raw/ua-pop-2022.xlsx" | ||
# ---- declare-functions ------------------------------------------------------- | ||
|
||
# ---- load-data --------------------------------------------------------------- | ||
ds0 <- readxl::read_xlsx( | ||
path_data_input | ||
, sheet = "12-47" | ||
, skip = 5 | ||
, col_names = c("unit_ua","pop_count","unit_en" ) | ||
) | ||
ds0 %>% glimpse() | ||
ds0 | ||
# ---- inspect-data ------------------------------------------------------------ | ||
|
||
|
||
# ---- tweak-data -------------------------------------------------------------- | ||
|
||
|
||
# ---- table-1 ----------------------------------------------------------------- | ||
|
||
|
||
# ---- graph-1 ----------------------------------------------------------------- | ||
|
||
|
||
# ---- graph-2 ----------------------------------------------------------------- | ||
|
||
# ---- save-to-disk ------------------------------------------------------------ | ||
|
||
# ---- publish ------------------------------------------------------------ | ||
path <- "./analysis/ua-pop-2022/ua-pop-2022.Rmd" # connect with Rmd for publishing | ||
rmarkdown::render( | ||
input = path , | ||
output_format=c( | ||
"html_document" | ||
# "word_document" | ||
# "pdf_document" | ||
), | ||
clean=TRUE | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
--- | ||
title: "UA population in 2020" | ||
author: "First Last" | ||
date: "last Updated: `r Sys.Date()`" | ||
output: | ||
html_document: | ||
keep_md: yes | ||
toc: yes | ||
toc_float: yes | ||
code_folding: show | ||
theme: simplex | ||
highlight: tango | ||
editor_options: | ||
chunk_output_type: console | ||
--- | ||
|
||
This report ( add a brief description and the purpose of the report) | ||
Demonstration of the __ISOLATED__ template | ||
|
||
<!-- Set the working directory to the repository's base directory; this assumes the report is nested inside of two directories.--> | ||
```{r, echo=F, message=F} | ||
# cat("Working directory: ", getwd()) | ||
library(knitr) | ||
opts_knit$set(root.dir='../../') #Don't combine this call with any other chunk -especially one that uses file paths. | ||
``` | ||
|
||
```{r set_options, echo=F} | ||
# cat("Working directory: ", getwd()) # turn on to test the location | ||
report_render_start_time <- Sys.time() | ||
# set options shared by all chunks | ||
opts_chunk$set( | ||
results = 'show', | ||
message = FALSE, | ||
warning = FALSE, | ||
comment = NA, | ||
tidy = FALSE, | ||
# dpi = 400, # dots per inch, | ||
# out.width = "650px", # pixels, this affects only the markdown, not the underlying png file. The height will be scaled appropriately. | ||
fig.width = 6, # inches | ||
fig.height = 4, # inches | ||
fig.path = 'figure-png-iso/' # where figures are stored | ||
) | ||
echo_chunks <- FALSE #Toggle for debugging. | ||
message_chunks <- FALSE #Toggle for debugging. | ||
options(width=100) # number of characters to display in the output (dflt = 80) | ||
ggplot2::theme_set(ggplot2::theme_bw()) # common theme for all graphs | ||
read_chunk("./analysis/ua-pop-2022/ua-pop-2022.R") #This allows knitr to call chunks tagged in the underlying *.R file. | ||
``` | ||
|
||
# Environment | ||
|
||
<!-- Load packages, or at least verify they're available on the local machine. Suppress the output when loading packages. --> | ||
```{r load-packages, message=message_chunks} | ||
cat("Working directory: ", getwd()) # turn on to test the location | ||
``` | ||
|
||
<!-- Load the sources. Suppress the output when loading sources. --> | ||
```{r load-sources} | ||
source("./scripts/common-functions.R") | ||
``` | ||
|
||
<!-- Load any Global functions and variables declared in the R file. Suppress the output. --> | ||
```{r declare-globals} | ||
``` | ||
|
||
# Data | ||
|
||
```{r load-data, results='show', message=FALSE} | ||
``` | ||
|
||
```{r tweak-data,echo = echo_chunks, results='show', message=message_chunks} | ||
``` | ||
|
||
# Analysis | ||
|
||
```{r table-1, echo = echo_chunks, results='show', message=message_chunks} | ||
``` | ||
|
||
|
||
```{r graph-1, echo = echo_chunks, results='show', message=message_chunks} | ||
``` | ||
|
||
```{r graph-2, echo = echo_chunks, results='show', message=message_chunks} | ||
``` | ||
|
||
Session Information {#session-info} | ||
=========================================================================== | ||
|
||
For the sake of documentation and reproducibility, the current report was rendered in the following environment. Click the line below to expand. | ||
|
||
<details> | ||
<summary>Environment <span class="glyphicon glyphicon-plus-sign"></span></summary> | ||
```{r session-info, echo=FALSE} | ||
if( requireNamespace("devtools", quietly = TRUE) ) { | ||
devtools::session_info() | ||
} else { | ||
sessionInfo() | ||
} | ||
``` | ||
</details> | ||
|
||
```{r session-duration, echo=FALSE} | ||
report_render_duration_in_seconds <- round(as.numeric(difftime(Sys.time(), report_render_start_time, units="secs"))) | ||
``` | ||
|
||
Report rendered by `r Sys.info()["user"]` at `r strftime(Sys.time(), "%Y-%m-%d, %H:%M %z")` in `r report_render_duration_in_seconds` seconds. |
Oops, something went wrong.