Script Documentation

showing how the code works for my script
Author
Affiliations

Frankthetank

Wa DOH

DIQA

1 Here’s the set up

First we need to read in the external R script that lives in the repo.

Use knitr::read_chunk() to read that file, and then you can call the chunk of code you want to display here in the document.

Now, any time someone pushes an update to that external script in the repo, this website can automatically pull those changes and reflect the changes in code.

No more copy and paste!

setwd('..')
setwd('..')
knitr::read_chunk(file.path(getwd(),"external_script.R"))

here’s an intro about my code

2 Code

this code will:

  • go into your file folder
  • sort the files by datetime
  • choose the most recent file
  • select the file path
  • then read in the file path and assign it to df
(df <- airquality |>
  arrange(desc(Month)) |>
  as_tibble())
# A tibble: 153 × 6
   Ozone Solar.R  Wind  Temp Month   Day
   <int>   <int> <dbl> <int> <int> <int>
 1    96     167   6.9    91     9     1
 2    78     197   5.1    92     9     2
 3    73     183   2.8    93     9     3
 4    91     189   4.6    93     9     4
 5    47      95   7.4    87     9     5
 6    32      92  15.5    84     9     6
 7    20     252  10.9    80     9     7
 8    23     220  10.3    78     9     8
 9    21     230  10.9    75     9     9
10    24     259   9.7    73     9    10
# … with 143 more rows


Note: that code above comes from an external script. To call that code, all you need to do is the following, where the code chunk is blank but contains the name of the chunk in the external file - {r chunk-name}

```{r read-chunk}
#| eval: false
(df <- airquality |>
  arrange(desc(Month)) |>
  as_tibble())
```