Reproducing analyses from a persistant project repository
Humboldt-Universität zu Berlin
2024-06-24
Today we will…
Germany - Frankfurt
data
scripts
or code
, or whatever you preferdata
, add the three csv
files you presumably have in the same folder in your project (drag and drop them, or select the big green +
)
data_lifetime_pilot.csv
tidy_data_lifetime_pilot.csv
tidy_data_lifetime_pilot_dictionary.csv
scripts
folder add the scripts where we worked with the data:
scripts/
folderdata
folder, how you organise and name this folder on OSF is more flexible
data
folder)Checklist: Share data and code
At this point, your OSF project should
data/
and scripts/
CSV
files and 3 Quarto scriptsscripts/
will also contain the 3 PDF script outputsscripts/
setwd()
?here()
package within an R project.Rproj
file at the project root directoryrenv
package
renv
.Rproj
file won’t mean that the person who downloads it will also have our packages
here
package, and won’t even be able to use our code to load in the datarenv
package does
renv.lock
) which is a projectChecklist: Share renv.lock
Add the renv.lock
file to your OSF project repo (in the project root directory).
.Rprofile
file
source("renv/activate.R")
renv/activate.R
filerenv/activate.R
file in our OSF repo
renv
.Rprofile
in Finder
Some files are usually invisible on a Mac, such as those that start with dot (like .Rprofile
). This makes it difficult to simply drag and drop the .Rprofile
file to the OSF. To make such files viewable in Finder, navigate to the relevant project folder and use the keyboard shortcut Ctrl + Shift + Dot
. These files will then appear greyed out.
README.md
will ideally have information that is useful once the project is downloaded in its entirety
renv::restore()
to restore your project library (but this will only work if they’re using the same R version!)
For example, you could add something like this:
Checklist: Share .Rprofile
and renv/activate.R
Your project should now have
.Rprofile
in the project root directoryrenv/activate.R
in the project root directory
renv/
in the root directoryactivate.R
file in this renv/
folderREADME.md
file in the root directoryscripts/
Anonymize
, your name will be removed from the project
Anonymising your scripts (optional)
If you have a relatively large project with your name at the beginning of multiple scripts, it can be tedious to manually remove it. And you might not be sure you actually took your name out of everything!
This can be used using RStudio’s Global Find:
Cmd+Shift+F
[Anonymized for peer review]
), and hit “Replace All”Important: this will work for HTML and R/Quarto/Rmd scripts, but not for PDFs! so you might want to re-render all PDFs. As far as I can tell you have to re-render each PDF. If you’re working in a Quarto project (and not an .Rproj
), then you can use quarto render subfoldername --to pdf
in the Terminal to re-render only the OSF PDFs. We didn’t discuss Quarto projects in this course, however.
After the manuscript is accepted, you can then reverse this step: use the Global Find to replace [Anonymized for peer review]
with your name! This is why I suggest surrounding the phrase with []
, it ensures you don’t accidentally replace the string ‘anonymized for peer review’ elsewhere in your files (e.g., maybe you wrote in some analysis plan “all scripts will be anonymized for peer review”, which would then be changed to “all scripts will be Daniela Palleschi” if I had replaced Anonymized for peer review
with my name).
Today we…
R version 4.4.0 (2024-04-24)
Platform: aarch64-apple-darwin20
Running under: macOS Ventura 13.2.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
attached base packages:
[1] stats graphics grDevices datasets utils methods base
loaded via a namespace (and not attached):
[1] digest_0.6.35 fastmap_1.2.0 xfun_0.44 magrittr_2.0.3
[5] knitr_1.47 htmltools_0.5.8.1 rmarkdown_2.27 cli_3.6.2
[9] renv_1.0.7 compiler_4.4.0 rprojroot_2.0.4 here_1.0.1
[13] rstudioapi_0.16.0 tools_4.4.0 evaluate_0.23 Rcpp_1.0.12
[17] yaml_2.3.8 magick_2.8.3 rlang_1.1.4 jsonlite_1.8.8