Skip to content

Commit

Permalink
start targets
Browse files Browse the repository at this point in the history
  • Loading branch information
boyiguo1 committed Nov 30, 2022
1 parent 59378ef commit fe09693
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"hash": "71977170a32607ab4bbc95716c0fcd20",
"result": {
"markdown": "---\ntitle: \"Reproducibile Workflows with `targets`\"\nauthor: \n - name: Boyi Guo\n url: https://boyiguo1.github.io\n affiliation: Department of Biostatistics, Johns Hopkins\n affiliation_url: https://publichealth.jhu.edu\ndescription: \"A Make-line pipeline tool for creating reproducible workflows in R\"\ndate: 2022-12-01\ndraft: true\ncategories: [module 3, week 6, project management, targets]\nexecute:\n eval: false\n---\n\n\n\n\n<!-- Add interesting quote -->\n\n# Pre-lecture materials\n\n### Read ahead\n\n::: callout-note\n## Read ahead\n\n**Before class, you can prepare by reading the following materials:**\n\n1. <https://books.ropensci.org/targets/>\n2. <https://books.ropensci.org/targets/walkthrough.html>\n3. <https://boyiguo1.github.io/talks/2020-07-16-Reproducible-Analysis-Workflow.pdf>\n:::\n\n### Prerequisites\nBefore starting you must install the additional package:\n\n* `targets` - the R Workflows package\n* `usethis` - an automation package that simplifies project creation and setup\n* `renv` - a package manager in R\n\nYou can do this by calling\n\n\n::: {.cell}\n\n```{.r .cell-code}\ninstall.packages(\"usethis\")\ninstall.packages(\"targets\")\ninstall.packages(\"renv\")\n```\n:::\n\n\nor use the “Install Packages…” option from the “Tools” menu in RStudio.\n\n### Acknowledgements\n\nMaterial for this lecture was borrowed and adopted from\n\n- https://books.ropensci.org/targets/walkthrough.html\n\n# Learning objectives\n\n::: callout-note\n# Learning objectives\n\n**At the end of this lesson you will:**\n\n- setup up `targets` analytic pipeline\n- write and run a data analysis with `targets`\n- replicate and retrieve analysis results from a `targets` workflow\n:::\n\n# What is `targets`?\n\n\n# Why do we use `targets`?\n\n\n# How to use `targets`\n\n## Set up a `targets` workflow\n\n::: {.cell}\n\n```{.r .cell-code}\n# Start a new R project\nusethis::create_project(\"targets_eg\")\n# Config target workflow\ntargets::use_targets()\n```\n:::\n\n\n### (Optional) Version control packages with `renv`\n\n::: {.cell}\n\n```{.r .cell-code}\n# Config renv system\nrenv::init()\ntargets::tar_renv()\n```\n:::\n\n\nIf other people opens up this project on a different computer, `renv` will automatically install all the necessary packages, i.e. the same version.\n\n::: callout-tip\n### Important `renv` functions\nYou need to keep track of your R packages in this analysis, similar to you version control your files using `git`. You may need to call the following functions periodically, i.e. after you add/remove necessary packages.\n* `targets::tar_renv()` updates `_targets_packages.R` by gathering all packages in your analytic workflow \n* `renv::status()` shows which packages are outdated or not recorded\n* `renv::snapshot()` updates your packages version number\n* `renv::restore()` restores all missing packages or packages whose version number doesn't match with the most updated snapshot.\n\nFor more information, visit <https://rstudio.github.io/renv/articles/renv.html>\n:::\n\n## Understand the file system\n\n\n\n\n\n# Post-lecture materials\n\n### Final Questions\n\nHere are some post-lecture questions to help you think about the material discussed.\n\n::: callout-note\n### Questions\n\n1. Add here.\n:::\n\n### Additional Resources\n\n::: callout-tip\n- `targets` website <https://docs.ropensci.org/targets/>\n- The `targetopic`, a `targets` ecosystem <https://wlandau.github.io/targetopia/packages.html>\n- A tutorial & reproducible example on calculating residential segregation indices with decennial US census data <https://github.com/boyiguo1/Tutorial-Residential_Segregation_Score>\n:::\n",
"supporting": [],
"filters": [
"rmarkdown/pagebreak.lua"
],
"includes": {},
"engineDependencies": {},
"preserve": {},
"postProcess": true
}
}
83 changes: 77 additions & 6 deletions posts/2022-12-01-targets-proj-workflows/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ description: "A Make-line pipeline tool for creating reproducible workflows in R
date: 2022-12-01
draft: true
categories: [module 3, week 6, project management, targets]
execute:
eval: false
---

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

<!-- Add interesting quote -->

# Pre-lecture materials
Expand All @@ -22,15 +30,34 @@ categories: [module 3, week 6, project management, targets]

**Before class, you can prepare by reading the following materials:**

1. Add here.
2. Add here.
1. <https://books.ropensci.org/targets/>
2. <https://books.ropensci.org/targets/walkthrough.html>
3. <https://boyiguo1.github.io/talks/2020-07-16-Reproducible-Analysis-Workflow.pdf>
:::

### Prerequisites
Before starting you must install the additional package:

* `targets` - the R Workflows package
* `usethis` - an automation package that simplifies project creation and setup
* `renv` - a package manager in R

You can do this by calling

```{r}
#| eval: false
install.packages("usethis")
install.packages("targets")
install.packages("renv")
```

or use the “Install Packages…” option from the “Tools” menu in RStudio.

### Acknowledgements

Material for this lecture was borrowed and adopted from

- Add here.
- https://books.ropensci.org/targets/walkthrough.html

# Learning objectives

Expand All @@ -39,10 +66,52 @@ Material for this lecture was borrowed and adopted from

**At the end of this lesson you will:**

- Add here.
- setup up `targets` analytic pipeline
- write and run a data analysis with `targets`
- replicate and retrieve analysis results from a `targets` workflow
:::

# What is `targets`?


# Why do we use `targets`?


# How to use `targets`

## Set up a `targets` workflow
```{r}
# Start a new R project
usethis::create_project("targets_eg")
# Config target workflow
targets::use_targets()
```

### (Optional) Version control packages with `renv`
```{r}
# Config renv system
renv::init()
targets::tar_renv()
```

If other people opens up this project on a different computer, `renv` will automatically install all the necessary packages, i.e. the same version.

::: callout-tip
### Important `renv` functions
You need to keep track of your R packages in this analysis, similar to you version control your files using `git`. You may need to call the following functions periodically, i.e. after you add/remove necessary packages.
* `targets::tar_renv()` updates `_targets_packages.R` by gathering all packages in your analytic workflow
* `renv::status()` shows which packages are outdated or not recorded
* `renv::snapshot()` updates your packages version number
* `renv::restore()` restores all missing packages or packages whose version number doesn't match with the most updated snapshot.

For more information, visit <https://rstudio.github.io/renv/articles/renv.html>
:::

# Add lecture here
## Understand the file system





# Post-lecture materials

Expand All @@ -59,5 +128,7 @@ Here are some post-lecture questions to help you think about the material discus
### Additional Resources

::: callout-tip
- Add here.
- `targets` website <https://docs.ropensci.org/targets/>
- The `targetopic`, a `targets` ecosystem <https://wlandau.github.io/targetopia/packages.html>
- A tutorial & reproducible example on calculating residential segregation indices with decennial US census data <https://github.com/boyiguo1/Tutorial-Residential_Segregation_Score>
:::

0 comments on commit fe09693

Please sign in to comment.