The Open Science Framework (OSF) is an open-source online platform to facilitate collaboration and reproducibility in research. The OSF includes an online repository on which researchers deposit their data and analysis scripts to collaborate and make all steps of the research process transparent. The OSF is a spearhead of the Open Science movement, which has gathered much momentum in the last decade. We can encourage all meta-analysts to make their research and analysis process transparent to the public by providing open access to the collected data and R code used for the analyses. The OSF is a great tool to do this - all repositories you created for yourself are private by default, and it is up to you to decide if, when and what you want to make public. In the following, we will show you how to set up an OSF repository in R, upload and download files, and how to add collaborators.
17.3.1 Access Token
To start using the OSF, you first have to create a personal account here. After your account has been created, we have to generate an Access Token so that we can manipulate our repository directly in RStudio. To get an access token, we can use this link. On the site, click on Create token.
Then, under Scopes, check all boxes, and click on Create token again. After that, your personal access token should appear. Copy the token code and save it somewhere where only you can access it.
17.3.2 Installing the
osfr package & Authentication
To access OSF directly via R, we can use the
osfr package (Wolen and Hartgerink 2019). To install the package and load it from your library, use the following code:
Before I can start using the functionality of the
osfr package, I have to use the access token to authenticate. This process is necessary so that only I (or everyone who has access to the token) can change something in my repository. To authenticate, we use the
osf_auth function, providing it with the access token we just received (the token displayed below is made up and not my actual access token):
17.3.3 Setting up the repository
osfr, we can now initiate an online repository using R code. Let us assume that I am working on a new meta-analysis project, for which I want to upload my data and R Markdown script to an OSF repository, which I want to name “Meta-Analysis Project”. To create a project on osf.io, I can use the
osf_create_project function. I only have to plug in the name of the repository I want to create, and save it as an
R object called
meta_analysis_project <- osf_create_project("Meta-Analysis Project")
osf_open function, I can then access my newly created repository online:
Now that my repository has been created, I can proceed by adding components to it, which function like folder do on my computer. I want to create two components, one for my datasets, and one for my R Markdown scripts. To do this, I use the
osf_create_component function. I have to provide the function with the R object for my repository (
meta_analysis_project), and then set the title of the component. I save both components as objects into my R environment.
scripts <- osf_create_component(meta_analysis_project, title = "Analysis Scripts") datasets <- osf_create_component(meta_analysis_project, title = "Datasets")
If I go to the online page of my repository now, I see that the two components have been added.
17.3.4 Upload & Download
To upload data to the OSF repository, I can use the
osf_upload function. The function requires the component/folder to which I want to add the file (as the R object we saved previously), and the path to the file as input. Let us say that I want to upload an R Markdown script “Analysis.rmd”, which is currently saved in my R project subfolder “scripts”. To upload, the I can use the following code:
To see if the file has been uploaded successfully, I can access contents of the
scripts components using the
# A tibble: 2 x 3 name id meta <chr> <chr> <list> 1 Analysis.rmd 1db74s7bfcf91f0012567572l <named list >
Is can been seen in the output, the upload was successful. To download a file, I can select a row from the
osf_ls_files function output, and use this as input to the
osf_download function to download this specific file back into the project folder on my computer.
17.3.5 Collaboration & Public Access
On the website of my OSF repository, I can also add collaborators under the “Contributors” field.
At any time, I can also make my repository public by clicking on Make Public in the upper-right corner of the site.
Wolen, Aaron, and Chris Hartgerink. 2019. Osfr: R Interface to Osf.