Created
March 28, 2025 19:51
-
-
Save graebnerc/8bf1c6ec558a68b1a8320d77e7b3539b to your computer and use it in GitHub Desktop.
Lecture notes for lab 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| This contains a clean version of the scripts used during the lab. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # There are two ways to access a function from a package | |
| # Consider the function `mutate` from the package `dplyr` | |
| # First option: | |
| dplyr::mutate() # <- [name of package]::[name of object] | |
| # Second option: | |
| library(dplyr) # Attach the package | |
| mutate() # use the function | |
| # The second option is easier, but bears the problem of masking functions from other packages | |
| # For more information see the tutorial: | |
| https://researchmethodology25spring.netlify.app/content/tutorials/first-steps/#r-packages |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| here::i_am("R/paths-here.R") # <- this line must be part of every scrip | |
| # It must provide the relative path to the script, relative to the working directory | |
| here::here() # Use function here from package here (same name for package and function!) | |
| # This function returns a string with the absolute path to your working directory | |
| # The string will always be tailored to the computer on which you call the function | |
| # Therefore, your script is portable! | |
| here::here("data/example.csv") # <- if you pass a relative path to the function, it | |
| # constructs an absolute path, tailored to the computer on which you call the function | |
| # NOTE: this function just creates the path, it does not reads the file or anything else! | |
| # For more information see the tutorial: | |
| # https://researchmethodology25spring.netlify.app/content/tutorials/setting-up-an-r-project/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment