diff --git a/R/diagram-overviews.R b/R/diagram-overviews.R index 72c2342..828dfcb 100644 --- a/R/diagram-overviews.R +++ b/R/diagram-overviews.R @@ -1,5 +1,3 @@ -library(DiagrammeRsvg) -library(rsvg) library(here) #' Create a diagram of the overview of the course and workflow. @@ -81,7 +79,6 @@ diagram_overview <- function(section_num = 0) { }" graph_viz_text <- glue::glue(graphviz_template_text, .open = "((", .close = "))") - DiagrammeR::grViz(graph_viz_text) } save_diagram_to_svg <- function(number, output_file) { @@ -91,8 +88,14 @@ save_diagram_to_svg <- function(number, output_file) { rsvg_svg(output_file) } -save_diagram_to_svg(0, here("images/overview.svg")) -save_diagram_to_svg(1:2, here("images/overview-download-data.svg")) -save_diagram_to_svg(2, here("images/overview-workflow.svg")) -save_diagram_to_svg(2:3, here("images/overview-create-project-data.svg")) -save_diagram_to_svg(4, here("images/overview-analyze-project-data.svg")) +# save_diagram_to_svg(0, here("images/overview.svg")) +# save_diagram_to_svg(1:2, here("images/overview-download-data.svg")) +# save_diagram_to_svg(2, here("images/overview-workflow.svg")) +# save_diagram_to_svg(2:3, here("images/overview-create-project-data.svg")) +# save_diagram_to_svg(4, here("images/overview-analyze-project-data.svg")) + +diagram_overview(0) |> readr::write_lines(here("images/overview.mmd")) +# diagram_overview(1:2, here("images/overview-download-data.mmd")) +# diagram_overview(2, here("images/overview-workflow.mmd")) +# diagram_overview(2:3, here("images/overview-create-project-data.mmd")) +# diagram_overview(4, here("images/overview-analyze-project-data.mmd")) diff --git a/images/raw/function-creation-flow.mmd b/images/raw/function-creation-flow.mmd new file mode 100644 index 0000000..378c607 --- /dev/null +++ b/images/raw/function-creation-flow.mmd @@ -0,0 +1,8 @@ +flowchart + code --> + fn_wrap --> + add_args --> + insert_args --> + include_output --> + test --> + insert_docs diff --git a/images/raw/restart-flow.mmd b/images/raw/restart-flow.mmd new file mode 100644 index 0000000..b7738f0 --- /dev/null +++ b/images/raw/restart-flow.mmd @@ -0,0 +1,8 @@ +flowchart + code(Write code) --> as_function + as_function --> test + test --> fix_function + fix_function --> test + fix_function --> restart + restart --> test + restart --> code diff --git a/sessions/functionals.qmd b/sessions/functionals.qmd index ac741d2..22174fa 100644 --- a/sessions/functionals.qmd +++ b/sessions/functionals.qmd @@ -25,12 +25,19 @@ and remind everyone the 'what' and 'why' of what we are doing. ## Learning objectives -The learning objectives of this session are: +The overall learning outcome for this session is to: -1. Learn about and apply functional programming, vectorization, and - functionals within R. -2. Review the split-apply-combine technique and understand the link - with functional programming. +1. Describe a basic workflow for creating functions and then apply this + workflow to import data. + +Specific objectives are to: + +1. Explain what functional programming, vectorization, and functionals + are within R and identify when code is a functional or uses + functional programming. Then to apply this knowledge by using the + `{purrr}` package. +2. Review the split-apply-combine technique and identify how these + concepts connect to functional programming. 3. Apply functional programming to summarizing data and for using the split-apply-combine technique. @@ -733,15 +740,6 @@ list(average = mean) list(ave = mean) ``` -You can confirm that it is a list by using the function `names()`: - -```{r} -#| filename: "Console" -names(list(mean = mean)) -names(list(average = mean)) -names(list(ave = mean)) -``` - Let's stick with `list(mean = mean)`: ```{r} diff --git a/sessions/functions.qmd b/sessions/functions.qmd index ae2c039..a42b564 100644 --- a/sessions/functions.qmd +++ b/sessions/functions.qmd @@ -4,6 +4,7 @@ #| include: false library(fs) library(tidyverse) +library(readr) library(here) load(here("_temp/importing.RData")) temp_path <- fs::path_temp() @@ -23,16 +24,29 @@ covering.](/images/overview-workflow.svg){#fig-overview-workflow} ## Learning objectives -The learning objectives of this session are: - -1. Learn what functions are in R and how to create and use them. -2. Learn a workflow of using Quarto, `source()` with - {{< var keybind.source >}} and restarting R with - {{< var keybind.restart-r >}} as a tool and process for developing - functions that can be later easily (re-)used. -3. Learn what R package dependency management is and how it can - simplify your data analysis work. -4. Continue practising Git version control to manage changes to your +The overall learning outcome for this session is to: + +1. Describe a basic workflow for creating functions and then apply this + workflow to import data. + +Specific objectives are to: + +1. Describe and identify the individual components of a function as + well as the workflow to creating them, and then use this workflow to + make one to import some data. +2. Describe a workflow for developing code that combines using Quarto, + `source()`'ing with {{< var keybind.source >}}, and restarting R + with {{< var keybind.restart-r >}}, explain its usefulness in + assessing correctness and re-usability of code, and then apply this + workflow when developing functions. +3. Explain what R package dependency management is, why it is necessary + when writing code and ensuring reproducibility, and apply tools like + `usethis::use_package()` to manage dependencies in an R project. +4. Describe and apply a workflow of prototyping code in a Quarto + document and then moving it into a script (called, e.g., + `functions.R`) once finished and tested, then using `source()` to + load the functions into the R session. +5. Continue practicing Git version control to manage changes to your files. ## The basics of a function diff --git a/sessions/importing.qmd b/sessions/importing.qmd index f2222c6..d648cc7 100644 --- a/sessions/importing.qmd +++ b/sessions/importing.qmd @@ -32,33 +32,6 @@ we'll continue the process by now importing it into R. ![Section of the overall workflow we will be covering.](/images/overview-download-data.svg){#fig-overview-download-data} -Right now, your folder and file structure should look like (use -`fs::dir_tree(recurse = 2)` if you want to check using R): - -``` -LearnR3 -├── data/ -│ └── README.md -├── data-raw/ -│ ├── README.md -│ ├── mmash-data.zip -│ ├── mmash/ -│ │ ├── user_1 -│ │ ├── ... -│ │ └── user_22 -│ └── mmash.R -├── doc/ -│ ├── README.md -│ └── lesson.qmd -├── R/ -│ ├── functions.R -│ └── README.md -├── .gitignore -├── DESCRIPTION -├── LearnR3.Rproj -└── README.md -``` - ## Learning objectives The overall learning outcome for this session is to: