Skip to content

Commit

Permalink
Merge commit 'd15aeb197e36a8f2651bd76d78ff5bc48322b171'
Browse files Browse the repository at this point in the history
#Conflicts:
#	sessions/functionals.qmd
#	sessions/functions.qmd
  • Loading branch information
lwjohnst86 committed May 5, 2024
2 parents e7d663b + d15aeb1 commit a97a986
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 59 deletions.
19 changes: 11 additions & 8 deletions R/diagram-overviews.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
library(DiagrammeRsvg)
library(rsvg)
library(here)

#' Create a diagram of the overview of the course and workflow.
Expand Down Expand Up @@ -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) {
Expand All @@ -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"))
8 changes: 8 additions & 0 deletions images/raw/function-creation-flow.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
flowchart
code -->
fn_wrap -->
add_args -->
insert_args -->
include_output -->
test -->
insert_docs
8 changes: 8 additions & 0 deletions images/raw/restart-flow.mmd
Original file line number Diff line number Diff line change
@@ -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
26 changes: 12 additions & 14 deletions sessions/functionals.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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}
Expand Down
34 changes: 24 additions & 10 deletions sessions/functions.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#| include: false
library(fs)
library(tidyverse)
library(readr)
library(here)
load(here("_temp/importing.RData"))
temp_path <- fs::path_temp()
Expand All @@ -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
Expand Down
27 changes: 0 additions & 27 deletions sessions/importing.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a97a986

Please sign in to comment.