Wednesday, August 8, 2012

Get a path to your Dropbox folder

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.

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).


9 comments:

  1. Being relatively new to R, I understand the first 5 lines of code, but could you explain me the purpose of the second halve with the whole intup.file/output.file thing? Isn't there a simpler way to do this than messing around with creating temporary files?

    ReplyDelete
  2. And would this work (seems more elegant than invoking a shell):

    db.file <- paste(paste(Sys.getenv('APPDATA'), '\\Dropbox\\host.db', sep='')

    ReplyDelete
  3. Sorry for the multiple comments, but I think I start to understand what you were doing. If I am right, base64Decode from the RCurl package should be an easier way for base64 decoding without using the temporary files. However the Sys.getenv way I mentioned above should do the job without any en/decoding, is that right?

    ReplyDelete
    Replies
    1. Hi Wouter! You are right about base64 decoding. I did not know RCurl:::base64Decode function, so I tried Romain Francois's base64 package and that leaded to a dirty way with temporary files.

      Sys.getenv() returns %appdata% path but I believe there is no system variable with Dropbox folder path. Moreover, Dropbox folder can be located anywhere on the disk and actually I see the difference between my WinXP and Win7 machines (I might change defaults during the installation - I do not remember now).

      Anyway, thanks a lot - I updated the code and it is now more simple and easy to read.

      Delete
  4. If you are only using Windows why not just move Dropbox to the C drive on each machine? That way the paths are the same regardless of the machine.

    ReplyDelete
    Replies
    1. Generally, I agree - I could fix the Dropbox location on all computers (for example C:\Dropbox). There is a slight problem because some of them are used by multiple users.

      But I like hard ways :-)

      Delete
  5. Would you mind sharing the workflow you've come up with? (perhaps in another post) I'm interested in how others structure things on a practical level.

    ReplyDelete
  6. I tried to write something similar before. However, because I only work on 3 machines that I have 100% control of, I ended up using defining environment variables on each of the machines.

    ReplyDelete
  7. Unfortunately this no longer works. Dropbox has changed their db format, and at least on my system there is no host.db file anymore. I'm resorting to putting the dropbox path in an environment variable now.

    ReplyDelete