Last updated: 2020-10-26

Checks: 7 0

Knit directory: r4ds_book/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20200814) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version b7ebd72. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rproj.user/

Untracked files:
    Untracked:  analysis/images/
    Untracked:  code_snipp.txt

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/ch21_rmd.Rmd) and HTML (docs/ch21_rmd.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
html 8224544 sciencificity 2020-10-26 Build site.
Rmd beacfd5 sciencificity 2020-10-26 added Ch21

options(scipen=10000)
library(tidyverse)
library(flair)
library(emo)
library(lubridate)
library(magrittr)
library(tidyquant)
theme_set(theme_tq())

Overview of commands

Text formatting 
------------------------------------------------------------

*italic*  or _italic_
**bold**   __bold__
`code`
superscript^2^ and subscript~2~

Headings
------------------------------------------------------------

# 1st Level Header

## 2nd Level Header

### 3rd Level Header

Lists
------------------------------------------------------------

*   Bulleted list item 1

*   Item 2

    * Item 2a

    * Item 2b

1.  Numbered list item 1

1.  Item 2. The numbers are incremented automatically in the output.

Links and images
------------------------------------------------------------

<http://example.com>

[linked phrase](http://example.com)

![optional caption text](path/to/img.png)

Tables 
------------------------------------------------------------

First Header  | Second Header
------------- | -------------
Content Cell  | Content Cell
Content Cell  | Content Cell


---
title: "Mock CV"
author: "Vebash Naidoo"
date: "25/10/2020"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE,
                     message = FALSE)
```

## CV of Vebash Naidoo

### Education

- BSc Computer Science and Applied Mathematics
- BSc Computer Science Honours [^1]
- Bachelor of Banking
- MBA

***

### Employment

1. Denel Aviation: Software Engineer in the Weapons Division
1. Rand Merchant Bank: Quantitative Business Analyst specialising in Credit
and Market Risk.

> “Why, sometimes I've believed as many as six impossible things before breakfast.”
> 
> <U+2015> Lewis Carroll, Alice in Wonderland


[^1] Here is a footnote

Mock CV

Options

The following table summarises which types of output each option suppresses:

Option Run code Show code Output Plots Messages Warnings
eval = FALSE - - - - -
include = FALSE - - - - -
echo = FALSE -
results = "hide" -
fig.show = "hide" -
message = FALSE -
warning = FALSE -


The code below generates Table @ref(tab:kable).

knitr::kable(
  mtcars[1:5, ],
  caption = "A knir table"
)
A knir table
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2

Caching

Each knit of a document starts from a completely clean slate.

  • Pro: great for reproducibility.

  • Con: It can be painful if you have some computations that take a long time.

  • The solution is cache = TRUE. When set, the output of the chunk is saved to a specially named file on disk. On subsequent runs, knitr will check to see if the code has changed, and if it hasn’t, it will reuse the cached results.

  • Note: The caching system must be used with care, because by default it is based on the code only, not its dependencies. For example, here the processed_data chunk depends on the raw_data chunk:

    
        ```{r raw_data}
        rawdata <- readr::read_csv("a_very_large_file.csv")
        ```
    
        ```{r processed_data, cache = TRUE}
        processed_data <- rawdata %>% 
          filter(!is.na(import_var)) %>% 
          mutate(new_variable = complicated_transformation(x, y, z))
        ```

    Caching the processed_data chunk means that it will get re-run if the dplyr pipeline is changed, but it won’t get rerun if the read_csv() call changes. You can avoid that problem with the dependson chunk option:

        ```{r processed_data, cache = TRUE, dependson = "raw_data"}
        processed_data <- rawdata %>% 
          filter(!is.na(import_var)) %>% 
          mutate(new_variable = complicated_transformation(x, y, z))
        ```

    dependson should contain a character vector of every chunk that the cached chunk depends on.

  • Note that the chunks won’t update if a_very_large_file.csv changes, because knitr caching only tracks changes within the .Rmd file. Use the cache.extra option to track changes to the file. The R expression will invalidate the cache whenever it changes. A good function to use is file.info(): it returns a bunch of information about the file including when it was last modified.

        ```{r raw_data, cache.extra = file.info("a_very_large_file.csv")}
        rawdata <- readr::read_csv("a_very_large_file.csv")
        ```
  • It’s a good idea to regularly clear out all your caches with knitr::clean_cache().

Inline code

comma <- function(x) format(x, digits = 2, big.mark = ',')
# `r comma(3452345)` to produce the inline result

This year has felt 3,452,345 days long. Formatting decimals is a breeze using the comma function: 0.12.

Exercises

  1. Set up a network of chunks where d depends on c and b, and both b and c depend on a. Have each chunk print lubridate::now(), set cache = TRUE, then verify your understanding of caching.

    ---
    title: "Ch21 Exercise"
    author: "Vebash Naidoo"
    date: "26/10/2020"
    output: html_document
    params:
      date_now: !r lubridate::now()
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE,
                          cache = TRUE)
    library(tidyverse)
    ```
    
    ```{r a}
    print(params$date_now)
    print(lubridate::now())
    x <- 20
    y <- rnorm(10)
    z <- tibble(x, y)
    z
    # comment added after 05:37:05
    ```
    
    ```{r b, dependson = "a"}
    print(lubridate::now())
    x <- 20
    y <- rnorm(10)
    z <- tibble(x, y)
    z
    ```
    
    ```{r c, dependson = c("a")}
    print(lubridate::now())
    x <- 20
    y <- rnorm(10)
    z <- tibble(x, y)
    z
    ```
    
    ```{r d, dependson = c("c","b")}
    print(lubridate::now())
    x <- 20
    y <- rnorm(10)
    z <- tibble(x, y)
    z
    ```
    
    



    Rendered file


sessionInfo()
#> R version 3.6.3 (2020-02-29)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 18363)
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=English_South Africa.1252  LC_CTYPE=English_South Africa.1252   
#> [3] LC_MONETARY=English_South Africa.1252 LC_NUMERIC=C                         
#> [5] LC_TIME=English_South Africa.1252    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#>  [1] tidyquant_1.0.0            quantmod_0.4.17           
#>  [3] TTR_0.23-6                 PerformanceAnalytics_2.0.4
#>  [5] xts_0.12-0                 zoo_1.8-7                 
#>  [7] magrittr_1.5               lubridate_1.7.8           
#>  [9] emo_0.0.0.9000             flair_0.0.2               
#> [11] forcats_0.5.0              stringr_1.4.0             
#> [13] dplyr_1.0.0                purrr_0.3.4               
#> [15] readr_1.3.1                tidyr_1.1.0               
#> [17] tibble_3.0.3               ggplot2_3.3.0             
#> [19] tidyverse_1.3.0            workflowr_1.6.2           
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.4.6     lattice_0.20-38  assertthat_0.2.1 rprojroot_1.3-2 
#>  [5] digest_0.6.25    R6_2.4.1         cellranger_1.1.0 backports_1.1.6 
#>  [9] reprex_0.3.0     evaluate_0.14    highr_0.8        httr_1.4.2      
#> [13] pillar_1.4.6     rlang_0.4.7      curl_4.3         readxl_1.3.1    
#> [17] rstudioapi_0.11  whisker_0.4      rmarkdown_2.4    munsell_0.5.0   
#> [21] broom_0.5.6      compiler_3.6.3   httpuv_1.5.2     modelr_0.1.6    
#> [25] xfun_0.13        pkgconfig_2.0.3  htmltools_0.5.0  tidyselect_1.1.0
#> [29] quadprog_1.5-8   fansi_0.4.1      crayon_1.3.4     dbplyr_1.4.3    
#> [33] withr_2.2.0      later_1.0.0      Quandl_2.10.0    grid_3.6.3      
#> [37] nlme_3.1-144     jsonlite_1.7.0   gtable_0.3.0     lifecycle_0.2.0 
#> [41] DBI_1.1.0        git2r_0.26.1     scales_1.1.0     cli_2.0.2       
#> [45] stringi_1.4.6    fs_1.4.1         promises_1.1.0   xml2_1.3.2      
#> [49] ellipsis_0.3.1   generics_0.0.2   vctrs_0.3.2      tools_3.6.3     
#> [53] glue_1.4.1       hms_0.5.3        yaml_2.2.1       colorspace_1.4-1
#> [57] rvest_0.3.5      knitr_1.28       haven_2.2.0