Get a path to your Dropbox folder
[This article was first published on Apply R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
I am currently designing my RStudio – Dropbox – Mardown/Knitter/Wordpress – Github workflow. One problem is that working on multiple machines with different version of Windows means I somehow need to tell R where my Dropbox folder is located.Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
I used to set the working directory at the beginning of my R scripts but it became tedious to change the path all the time. The solution might be to add definition of ‘dropbox.folder.path’ variable to .Rprofile files. Or there is a hard way – to write a script detecting Dropbox location automatically.
I have found this hint and created the script below. It is for Windows only (because I do not have Dropbox on the cluster). However, it should be easy to modify it for linux / MacOS if needed (see this shell script).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get.dropbox.folder <- function() { | |
if (!require(RCurl)) stop ("You need to install RCurl package.") | |
if (Sys.info()["sysname"]!="Windows") stop("Currently, 'get.dropbox.folder' works for Windows only. Sorry.") | |
db.file <- paste(Sys.getenv('APPDATA'), '\\Dropbox\\host.db', sep='') | |
base64coded <- readLines(db.file, warn=FALSE)[2] | |
base64(base64coded, encode=FALSE) | |
} |
To leave a comment for the author, please follow the link and comment on their blog: Apply R.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.