diff --git a/02-func-R.md b/02-func-R.md index fc5344356..c851ec33c 100644 --- a/02-func-R.md +++ b/02-func-R.md @@ -48,6 +48,8 @@ The list of argument names are contained within parentheses. Next, the [body](../learners/reference.md#function-body) of the function--the statements that are executed when it runs--is contained within curly braces (`{}`). The statements in the body are indented by two spaces, which makes the code easier to read but does not affect how the code operates. +![Vocabulary associated with functions.](fig/function-terminology.svg){alt="A screenshot of the function `fahrenheit_to_celsius` defined above with some extra text annotations on specific function elements. Above the text `fahrenheit_to_celsisus`, the text reads 'Function name'. Above the text `temp_F`, the text reads 'Function argument(s)'.' The next two lines, surrounded by curly braces, are labelled 'Function body'."} + When we call the function, the values we pass to it are assigned to those variables so that we can use them inside the function. Inside the function, we use a [return statement](../learners/reference.md#return-statement) to send a result back to whoever asked for it. diff --git a/config.yaml b/config.yaml new file mode 100644 index 000000000..26210599d --- /dev/null +++ b/config.yaml @@ -0,0 +1,95 @@ +#------------------------------------------------------------ +# Values for this lesson. +#------------------------------------------------------------ + +# Which carpentry is this (swc, dc, lc, or cp)? +# swc: Software Carpentry +# dc: Data Carpentry +# lc: Library Carpentry +# cp: Carpentries (to use for instructor training for instance) +# incubator: The Carpentries Incubator +carpentry: 'swc' + +# Overall title for pages. +title: 'Programming with R' + +# Date the lesson was created (YYYY-MM-DD, this is empty by default) +created: '2014-12-18' + +# Comma-separated list of keywords for the lesson +keywords: 'software, data, lesson, The Carpentries' + +# Life cycle stage of the lesson +# possible values: pre-alpha, alpha, beta, stable +life_cycle: 'stable' + +# License of the lesson materials (recommended CC-BY 4.0) +license: 'CC-BY 4.0' + +# Link to the source repository for this lesson +source: 'https://github.com/swcarpentry/r-novice-inflammation' + +# Default branch of your lesson +branch: 'main' + +# Who to contact if there are any issues +contact: 'team@carpentries.org' + +# Navigation ------------------------------------------------ +# +# Use the following menu items to specify the order of +# individual pages in each dropdown section. Leave blank to +# include all pages in the folder. +# +# Example ------------- +# +# episodes: +# - introduction.md +# - first-steps.md +# +# learners: +# - setup.md +# +# instructors: +# - instructor-notes.md +# +# profiles: +# - one-learner.md +# - another-learner.md + +# Order of episodes in your lesson +episodes: +- 01-starting-with-data.Rmd +- 02-func-R.Rmd +- 03-loops-R.Rmd +- 04-cond.Rmd +- 05-cmdline.Rmd +- 06-best-practices-R.Rmd +- 07-knitr-R.Rmd +- 08-making-packages-R.Rmd +- 09-supp-intro-rstudio.Rmd +- 10-supp-addressing-data.Rmd +- 11-supp-read-write-csv.Rmd +- 12-supp-factors.Rmd +- 13-supp-data-structures.Rmd +- 14-supp-call-stack.Rmd +- 15-supp-loops-in-depth.Rmd + +# Information for Learners +learners: + +# Information for Instructors +instructors: + +# Learner Profiles +profiles: + +# Customisation --------------------------------------------- +# +# This space below is where custom yaml items (e.g. pinning +# sandpaper and varnish versions) should live + + +url: 'https://swcarpentry.github.io/r-novice-inflammation' +analytics: carpentries +lang: en diff --git a/data/car-speeds-cleaned.csv b/data/car-speeds-cleaned.csv index 2fde82b68..b7634a648 100644 --- a/data/car-speeds-cleaned.csv +++ b/data/car-speeds-cleaned.csv @@ -5,3 +5,97 @@ "White",34,"Arizona" "Red",25,"Arizona" "Blue",41,"Arizona" +"Blue",34,"NewMexico" +"Black",29,"Colorado" +"White",31,"Arizona" +"Red",26,"Colorado" +"Red",43,"Utah" +"White",26,"Utah" +"Blue",45,"Utah" +"Blue",49,"Utah" +"Black",33,"Utah" +"Red",53,"NewMexico" +"Blue",27,"Arizona" +"Blue",29,"NewMexico" +"White",27,"Arizona" +"Blue",42,"Utah" +"Blue",37,"Utah" +"Blue",42,"Utah" +"Red",48,"NewMexico" +"Blue",26,"Colorado" +"Red",40,"Colorado" +"Red",43,"NewMexico" +"Red",43,"Colorado" +"Red",25,"Utah" +"White",51,"Colorado" +"Blue",48,"Utah" +"Red",54,"NewMexico" +"White",36,"Colorado" +"Black",37,"Colorado" +"Red",38,"Utah" +"Black",33,"Colorado" +"Black",51,"Colorado" +"Blue",28,"NewMexico" +"Red",34,"Arizona" +"Black",54,"Utah" +"Red",47,"Colorado" +"Black",48,"Colorado" +"Black",53,"NewMexico" +"Red",32,"Arizona" +"Red",46,"Utah" +"White",34,"Arizona" +"Black",46,"Colorado" +"Blue",34,"NewMexico" +"Red",43,"NewMexico" +"Red",34,"NewMexico" +"Black",33,"Colorado" +"Black",43,"Arizona" +"Red",41,"Utah" +"White",42,"Utah" +"Red",45,"Arizona" +"Blue",52,"NewMexico" +"Blue",39,"Colorado" +"Black",29,"Utah" +"Blue",27,"Colorado" +"White",30,"Utah" +"Black",31,"Utah" +"Red",29,"Utah" +"Blue",27,"Colorado" +"Blue",50,"NewMexico" +"White",53,"Colorado" +"Black",50,"NewMexico" +"Red",46,"Colorado" +"Red",26,"NewMexico" +"Black",32,"Arizona" +"Blue",54,"NewMexico" +"White",36,"Utah" +"Blue",48,"Utah" +"Red",29,"Colorado" +"White",44,"Arizona" +"White",38,"Utah" +"Blue",49,"Colorado" +"Blue",52,"Colorado" +"Blue",36,"Colorado" +"Blue",45,"Arizona" +"Blue",34,"NewMexico" +"White",31,"Arizona" +"Black",44,"Utah" +"Blue",32,"Colorado" +"White",53,"Colorado" +"Black",34,"Arizona" +"Black",25,"Arizona" +"Red",41,"Arizona" +"Red",43,"Utah" +"White",41,"Arizona" +"White",40,"Utah" +"White",52,"Utah" +"White",44,"Utah" +"Red",34,"Arizona" +"Red",41,"Arizona" +"Red",31,"NewMexico" +"White",25,"Colorado" +"Black",46,"Colorado" +"White",34,"Utah" +"Black",25,"NewMexico" +"Black",32,"Arizona" +"White",42,"Utah" diff --git a/fig/function-terminology.svg b/fig/function-terminology.svg new file mode 100644 index 000000000..a9ea19394 --- /dev/null +++ b/fig/function-terminology.svg @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + 2 + + + + + + 3 + + These are the values that arepassed to your function + Function argument(s) + Function body + Function name + This is the name of the objectthat stores the created function. + This is the command that thefunction will perform. A returnstatement is included to definewhat will be returned by thefunction. + diff --git a/md5sum.txt b/md5sum.txt index 149aa539d..09fc6bb49 100644 --- a/md5sum.txt +++ b/md5sum.txt @@ -4,7 +4,7 @@ "config.yaml" "c198bba3496d5a77c7b4ab59e81194f8" "site/built/config.yaml" "2024-04-02" "index.md" "df0cbbfded289fe4a899db2c1655b342" "site/built/index.md" "2024-04-02" "episodes/01-starting-with-data.Rmd" "32ebb9a53c8fac58d58a31ea346748cd" "site/built/01-starting-with-data.md" "2024-04-02" -"episodes/02-func-R.Rmd" "dfd6013d11abc9d57030e3cc65153297" "site/built/02-func-R.md" "2024-04-02" +"episodes/02-func-R.Rmd" "25f5fc590f8e88e5392f1ee13b182a48" "site/built/02-func-R.md" "2024-04-07" "episodes/03-loops-R.Rmd" "5f4c204ffd96681509368665a212e66e" "site/built/03-loops-R.md" "2024-04-02" "episodes/04-cond.Rmd" "6c75b64cafdd5473d6dff10b45c123b1" "site/built/04-cond.md" "2024-04-02" "episodes/05-cmdline.Rmd" "cfcc57d0b46dfab9eb97670ed6e1aeaa" "site/built/05-cmdline.md" "2024-04-02" diff --git a/renv.lock b/renv.lock new file mode 100644 index 000000000..5118db33c --- /dev/null +++ b/renv.lock @@ -0,0 +1,342 @@ +{ + "R": { + "Version": "4.3.3", + "Repositories": [ + { + "Name": "carpentries", + "URL": "https://carpentries.r-universe.dev" + }, + { + "Name": "carpentries_archive", + "URL": "https://carpentries.github.io/drat" + }, + { + "Name": "CRAN", + "URL": "https://cran.rstudio.com" + } + ] + }, + "Packages": { + "R6": { + "Package": "R6", + "Version": "2.5.1", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R" + ], + "Hash": "470851b6d5d0ac559e9d01bb352b4021" + }, + "base64enc": { + "Package": "base64enc", + "Version": "0.1-3", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R" + ], + "Hash": "543776ae6848fde2f48ff3816d0628bc" + }, + "bslib": { + "Package": "bslib", + "Version": "0.7.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "base64enc", + "cachem", + "fastmap", + "grDevices", + "htmltools", + "jquerylib", + "jsonlite", + "lifecycle", + "memoise", + "mime", + "rlang", + "sass" + ], + "Hash": "8644cc53f43828f19133548195d7e59e" + }, + "cachem": { + "Package": "cachem", + "Version": "1.0.8", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "fastmap", + "rlang" + ], + "Hash": "c35768291560ce302c0a6589f92e837d" + }, + "cli": { + "Package": "cli", + "Version": "3.6.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "utils" + ], + "Hash": "1216ac65ac55ec0058a6f75d7ca0fd52" + }, + "digest": { + "Package": "digest", + "Version": "0.6.35", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "utils" + ], + "Hash": "698ece7ba5a4fa4559e3d537e7ec3d31" + }, + "evaluate": { + "Package": "evaluate", + "Version": "0.23", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "methods" + ], + "Hash": "daf4a1246be12c1fa8c7705a0935c1a0" + }, + "fastmap": { + "Package": "fastmap", + "Version": "1.1.1", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "f7736a18de97dea803bde0a2daaafb27" + }, + "fontawesome": { + "Package": "fontawesome", + "Version": "0.5.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "htmltools", + "rlang" + ], + "Hash": "c2efdd5f0bcd1ea861c2d4e2a883a67d" + }, + "fs": { + "Package": "fs", + "Version": "1.6.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "methods" + ], + "Hash": "47b5f30c720c23999b913a1a635cf0bb" + }, + "glue": { + "Package": "glue", + "Version": "1.7.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "methods" + ], + "Hash": "e0b3a53876554bd45879e596cdb10a52" + }, + "highr": { + "Package": "highr", + "Version": "0.10", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "xfun" + ], + "Hash": "06230136b2d2b9ba5805e1963fa6e890" + }, + "htmltools": { + "Package": "htmltools", + "Version": "0.5.8", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "base64enc", + "digest", + "fastmap", + "grDevices", + "rlang", + "utils" + ], + "Hash": "149431ee39aba5bdc264112c8ff94444" + }, + "jquerylib": { + "Package": "jquerylib", + "Version": "0.1.4", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "htmltools" + ], + "Hash": "5aab57a3bd297eee1c1d862735972182" + }, + "jsonlite": { + "Package": "jsonlite", + "Version": "1.8.8", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "methods" + ], + "Hash": "e1b9c55281c5adc4dd113652d9e26768" + }, + "knitr": { + "Package": "knitr", + "Version": "1.45", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "evaluate", + "highr", + "methods", + "tools", + "xfun", + "yaml" + ], + "Hash": "1ec462871063897135c1bcbe0fc8f07d" + }, + "lifecycle": { + "Package": "lifecycle", + "Version": "1.0.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "glue", + "rlang" + ], + "Hash": "b8552d117e1b808b09a832f589b79035" + }, + "memoise": { + "Package": "memoise", + "Version": "2.0.1", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "cachem", + "rlang" + ], + "Hash": "e2817ccf4a065c5d9d7f2cfbe7c1d78c" + }, + "mime": { + "Package": "mime", + "Version": "0.12", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "tools" + ], + "Hash": "18e9c28c1d3ca1560ce30658b22ce104" + }, + "rappdirs": { + "Package": "rappdirs", + "Version": "0.3.3", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R" + ], + "Hash": "5e3c5dc0b071b21fa128676560dbe94d" + }, + "renv": { + "Package": "renv", + "Version": "1.0.5", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "utils" + ], + "Hash": "32c3f93e8360f667ca5863272ec8ba6a" + }, + "rlang": { + "Package": "rlang", + "Version": "1.1.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "utils" + ], + "Hash": "42548638fae05fd9a9b5f3f437fbbbe2" + }, + "rmarkdown": { + "Package": "rmarkdown", + "Version": "2.26", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "bslib", + "evaluate", + "fontawesome", + "htmltools", + "jquerylib", + "jsonlite", + "knitr", + "methods", + "tinytex", + "tools", + "utils", + "xfun", + "yaml" + ], + "Hash": "9b148e7f95d33aac01f31282d49e4f44" + }, + "sass": { + "Package": "sass", + "Version": "0.4.9", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R6", + "fs", + "htmltools", + "rappdirs", + "rlang" + ], + "Hash": "d53dbfddf695303ea4ad66f86e99b95d" + }, + "tinytex": { + "Package": "tinytex", + "Version": "0.50", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "xfun" + ], + "Hash": "be7a76845222ad20adb761f462eed3ea" + }, + "xfun": { + "Package": "xfun", + "Version": "0.43", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "grDevices", + "stats", + "tools" + ], + "Hash": "ab6371d8653ce5f2f9290f4ec7b42a8e" + }, + "yaml": { + "Package": "yaml", + "Version": "2.3.8", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "29240487a071f535f5e5d5a323b7afbd" + } + } +}