Error in beep(): could not find function "beep"
Three principles of naming files
(Jenny Bryan)
for the purposes of this course an additional principle is that file names follow
README file is the first file users read. In our case a user might be our future self, a teammate, or (if open source) anyone.
There can be multiple README files within a single directory: e.g. for the general project folder and then for a data subfolder. Data folder README’s can possibly contain codebook (data dictionary).
It should be brief but detailed enough to help user navigate.
a README should be up-to-date (can be updated throughout a project’s lifecycle as needed).
On GitHub we use markdown for README file (README.md
). Good news: emojis are supported.
Default
Microsoft products have Copyright. Images used based on fair use for educational purposes.
Optional
When you download R, you actually download base R.
But there are MANY optional packages you can download.
Good part: There is an R package for (almost) everything, from complex statistical modeling packages to baby names.
Bad part: At the beginning it can feel overwhelming.
All this time we have actually been using R packages.
What do R packages have? All sorts of things but mainly
functions
datasets
Try running the following code:
Why are we seeing this error?
Installing packages
install.packages()
In your Console, install the beepr package
We do this in the Console because we only need to do it once.
Packages Pane > Install
If you save your file and using a package RStudio will tell you that you have not installed the package.
Using packages
Option 1
More common usage.
Useful if you are going to use multiple functions from the same package. E.g. we have used many functions (ggplot, aes, geom_…) from the ggplot2 package. In such cases, usual practice is to put the library name in the first R chunk in the .Rmd file.
Option 2
Useful when you are going to use a function once or few times. Also useful if there are any conflicts. For instance if there is some other package in your environment that has a beep() function that prints the word beep, you would want to distinguish the beep function from the beepr package and the beep function from the other imaginary package.
Any one around the world can create R packages.
Good part: We are able to do pretty much anything R because someone from around the world has developed the package and shared it.
Bad part: The language can be inconsistent.
Good news: We have tidyverse.
The tidyverse is an opinionated collection of R packages designed for data science. All packages share an underlying design philosophy, grammar, and data structures. tidyverse.org
In short, tidyverse is a family of packages. From practical stand point, you can install many tidyverse packages at once (and you did this).
We can also load multiple tidyverse packages all at the same time.
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Refer back to older slides and identify the packages for each of the functions we commonly use in this class.
Importing data will depend on where the dataset is on your computer. However we use the help of here::here()
function. This function sets the working directory to the project folder (i.e. where the .Rproj
file is).
If each change is made by one collaborator at a time, this would not be an efficient workflow.
1 - commit
2 - pull (very important)
3 - push
We can create an issue to keep a list of mistakes to be fixed, ideas to check with teammates, or note a to-do task. You can assign tasks to yourself or teammates.
If you are working on an issue, it makes sense to refer to issue number in your commit message (e.g. “add first draft of alternate texts for #4”). If your commit resolves the issue then you can use key words such as “fixes #4” or “closes #4” to close the issue. Issues can also be manually closed.
A .gitignore file contains the list of files which Git has been explicitly told to ignore.
For instance README.html can be git ignored.
You may consider git ignoring confidential files (e.g. some datasets) so that they would not be pushed by mistake to GitHub.
A file can be git ignored either by point-and-click using RStudio’s Git pane or by adding the file path to the .gitignore file. For instance weather.csv data file in a data folder need to be added as data/weather.csv
Files with certain files (e.g. all .log files) can also be ignored. See git ignore patterns.
It is also a good practice to save session information as package versions change, in order to be able to reproduce results from an analysis we need to know under what technical conditions the analysis was conducted.
R version 4.4.1 (2024-06-14)
Platform: aarch64-apple-darwin20
Running under: macOS 15.0.1
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: America/Los_Angeles
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] lubridate_1.9.3 forcats_1.0.0 stringr_1.5.1 dplyr_1.1.4
[5] purrr_1.0.2 readr_2.1.5 tidyr_1.3.1 tibble_3.2.1
[9] ggplot2_3.5.1 tidyverse_2.0.0
loaded via a namespace (and not attached):
[1] gtable_0.3.5 jsonlite_1.8.9 compiler_4.4.1 tidyselect_1.2.1
[5] scales_1.3.0 yaml_2.3.10 fastmap_1.2.0 R6_2.5.1
[9] generics_0.1.3 knitr_1.48 munsell_0.5.1 pillar_1.9.0
[13] tzdb_0.4.0 rlang_1.1.4 utf8_1.2.4 stringi_1.8.4
[17] xfun_0.48 timechange_0.3.0 cli_3.6.3 withr_3.0.1
[21] magrittr_2.0.3 digest_0.6.37 grid_4.4.1 rstudioapi_0.16.0
[25] hms_1.1.3 lifecycle_1.0.4 vctrs_0.6.5 evaluate_1.0.1
[29] glue_1.8.0 fansi_1.0.6 colorspace_2.1-1 rmarkdown_2.28
[33] tools_4.4.1 pkgconfig_2.0.3 htmltools_0.5.8.1