From fe096932a76b9ca76a28f782802bb557a620914b Mon Sep 17 00:00:00 2001 From: Boyi Guo Date: Wed, 30 Nov 2022 09:33:20 -0500 Subject: [PATCH] start targets --- .../index/execute-results/html.json | 14 ++++ .../index.qmd | 83 +++++++++++++++++-- 2 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 _freeze/posts/2022-12-01-targets-proj-workflows/index/execute-results/html.json diff --git a/_freeze/posts/2022-12-01-targets-proj-workflows/index/execute-results/html.json b/_freeze/posts/2022-12-01-targets-proj-workflows/index/execute-results/html.json new file mode 100644 index 0000000..165f8dd --- /dev/null +++ b/_freeze/posts/2022-12-01-targets-proj-workflows/index/execute-results/html.json @@ -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\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. \n2. \n3. \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 \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 \n- The `targetopic`, a `targets` ecosystem \n- A tutorial & reproducible example on calculating residential segregation indices with decennial US census data \n:::\n", + "supporting": [], + "filters": [ + "rmarkdown/pagebreak.lua" + ], + "includes": {}, + "engineDependencies": {}, + "preserve": {}, + "postProcess": true + } +} \ No newline at end of file diff --git a/posts/2022-12-01-targets-proj-workflows/index.qmd b/posts/2022-12-01-targets-proj-workflows/index.qmd index 6bb6572..7325efd 100644 --- a/posts/2022-12-01-targets-proj-workflows/index.qmd +++ b/posts/2022-12-01-targets-proj-workflows/index.qmd @@ -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 +) +``` + # Pre-lecture materials @@ -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. +2. +3. ::: +### 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 @@ -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 ::: -# Add lecture here +## Understand the file system + + + + # Post-lecture materials @@ -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 +- The `targetopic`, a `targets` ecosystem +- A tutorial & reproducible example on calculating residential segregation indices with decennial US census data :::