0

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.

Community
  • 1
  • 1
Seb
  • 5,417
  • 7
  • 31
  • 50

2 Answers2

2

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

Buggy
  • 2,050
  • 21
  • 27
  • hmmm... does not work for me... returns `character(0)`. the directory seems not right: The `paste` part returns: `"C:\\Users\\Sebastian\\AppData\\Roaming/Dropbox"` which is not the right directory... – Seb Mar 14 '16 at 16:34
  • 1
    I have just checked it should work now. There was a typo in there. The paste part is the directory of the json file. File content (last line) has the true path – Buggy Mar 14 '16 at 16:38
0

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

wotter
  • 518
  • 5
  • 22