Closed jacobtnyoung closed 2 years ago
RMD files already have local awareness - when you knit they will use the local folder as the default directory.
(you might need to open R Studio by clicking on a specific RMD file - I have heard reports that behavior is not uniform across operating systems)
It depends on how your project folder is organized. If the lab and data files are in the same folder:
# project
# +-- lab.rmd
# +-- ltdb-data.csv
d <- read.csv( "ltdb-data.csv" )
Data in a data subdirectory:
# project
# +-- lab.rmd
# | data
# | +-- ltdb-data.csv
d <- read.csv( "data/ltdb-data.csv" )
In sibling directories:
# project
# | labs
# | +-- lab.rmd
# | data
# | +-- ltdb-data.csv
d <- read.csv( "../data/ltdb-data.csv" )
In a parent directory:
# project
# +-- ltdb-data.csv
# | labs
# | +-- lab.rmd
d <- read.csv( "../ltdb-data.csv" )
In R scripts you have to set the directory manually, which will be problematic because different team members would likely have different folder paths for the project.
setwd( ... )
Thus the creation of the here package and project settings.
Got it. Thanks.
In Lab 2, it asks us to use the
here()
function to open the"data/rodeo/ltdb_data_dictionary.csv"
file:This works when I have my R Project open. But, I don't see how it works when running the
utilties.R
script or when running the .Rmd file for the lab.How do you open an R Project from the .R script and the .Rmd file?