Reproducing analyses from a persistant public repository
Leibniz-Zentrum Allgemeine Sprachwissenschaft
Thu Oct 17, 2024
Germany - Frankfurt
data
scripts
or code
, or whatever you preferdata
, add the csv
file(s) you have in your project (drag and drop them, or select the big green +
)
scripts
folder add your scripts
Checklist: Share data and code
At this point, your OSF project should
data/
and scripts/
scripts/
will also contain the 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 project.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!)
renv
explanationFor example, you could add something like this:
Checklist: renv
files
Your project root directory should now have
renv.lock
(your lockfile).Rprofile
(the autoloader)renv/activate.R
(sets up renv
and our project library 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).
R version 4.4.1 (2024-06-14)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.6
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.45 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.1 rprojroot_2.0.4 here_1.0.1
[13] rstudioapi_0.16.0 tools_4.4.1 evaluate_0.24.0 Rcpp_1.0.12
[17] yaml_2.3.8 magick_2.8.3 rlang_1.1.4 jsonlite_1.8.8
OSF and Code Review