Reputation: 5507
I use R
on different systems and store my project within Dropbox. Suppose the following scenario:
System 1: setwd('c:/dropbox/...')
System 2: setwd('c:/users/anyuser/dropbox')
I have been thinking of a way to determine the dropbox path from within R
. Is there an elegant way to get obtain this directory? One possibility might be accessing registry keys, right?
Addendum: I think my Question is only loosely related to this question where the dropbox path seems to be in the user files only.
Upvotes: 0
Views: 2612
Reputation: 2100
WINDOWS ONLY
As described in the link from dropbox , you can grab it from your appdata / localappdata.
Here is how to do it via APPDATA / LOCALDATA.
library(jsonlite)
file_name<-list.files(paste(Sys.getenv(x = "APPDATA"),"Dropbox", sep="/"), pattern = "*.json", full.names = T)
if (length(file_name)==0){
file_name<-list.files(paste(Sys.getenv(x = "LOCALAPPDATA"),"Dropbox", sep="/"), pattern = "*.json", full.names = T)}
file_content<-fromJSON(txt=file_name)$personal
file_content<-file_content$path
I have assumed that you have a personal account not a business account. Otherwise replace $personal
with $business
in the second to last line.
P.S.: I can t completely verify it on this PC here. I will check it again later. <- Verfied, it should work now
Upvotes: 2
Reputation: 528
I use the same setup as you do, i.e. files on my dropbox with different paths on the various PCs i use.
I have solved the path problem by using RStudio projects. When you use projects in RStudio, you are more or less chrooted to the project directory and everything is in relative path from there (i.e. you define the location once on each machine and then forget about it). Tutorial here: https://support.rstudio.com/hc/en-us/articles/200526207-Using-Projects
Upvotes: 0