This package provides a programmatic interface to Dropbox from the R environment. The package is complete and fully working but waiting on a dependency to be updated on CRAN before it can be submitted.
Disclaimer: This package is fairly new and likely to contain bugs so please use discretion and report any issues here on github
Important: This package relies on
ROAuth 0.92 and the version currently available on CRAN does not play so well with
rDrop. Install the version on Duncan's github:
Without the newest
rDrop WILL NOT WORK!
Appon Dropbox from the Dropbox developer site. You will need to log in with your Dropbox username and password.Then, click Create An App.
.rprofileand no one else uses your computer, then we recommend you save your keys there by adding the following lines:
options(DropboxKey = "Your_App_key") options(DropboxSecret = "Your_App_Secret")
If you prefer not to specify keys in a
.rprofile (especially if you are on a public computer/cluster/the cloud), you can specify both keys in the
dropbox_auth() function directly (more on this below). Note that once you have authorized an app, there is no need to call this function again. You can just use your saved credential file to access your Dropbox. If for any reason, the credential file becomes compromised, just revoke access from your list of authorized apps and start over.
library(rDrop) # If you have Dropbox keys in your .rprofile, simply run: dropbox_credentials <- dropbox_auth() # Otherwise: dropbox_credentials <- dropbox_auth("Your_consumer_key", "Your_consumer_secret")
If you entered valid keys, you will be directed to a secure Dropbox page on your browser asking you to authorize the app you just created. Click authorize to add this to your approved app list and return to R. This is a one time authorization. Once you have completed these steps, return to
R. There is no need to run
dropbox_auth() for each subsequent run. Simply save your credentials file to disk and load as needed:
Credentials will remain valid until you revoke them from your Dropbox Apps page by clicking the x next to your App's name.
This package essentially provides standard Dropbox file operation functions (create/copy/move/restore/share) from within
To load a previously validated Dropbox credential file:
load('/path/to/my_dropbox_credentials.rdata') # or once again run, dropbox_credentials <- dropbox_auth('Your_consumer_key', 'Your_consumer_secret')
dropbox_acc_info(dropbox_credentials) # will return a list with your display name, email, quota, referral URL, and country.
dropbox_dir(dropbox_credentials) # To list files and folders in your Dropbox root. dropbox_dir(dropbox_credentials, pattern=".rdata") # To list files and folders matching a pattern. Any regex should work. dropbox_dir(dropbox_credentials, verbose = TRUE) # for a complete listing (filename, revision, thumb, bytes, modified, path, and is_dir) with detailed information. dropbox_dir(dropbox_credentials, path = 'folder_name') # To see contents of a specified path. dropbox_dir(dropbox_credentials, path = 'folder_name', verbose = TRUE) # For verbose content listing for a specified path (relative to Dropbox root).
# Reading text files file <- dropbox_get(dropbox_credentials, 'my_data.csv') data <- read.csv(textConnection(file)) # Reading CSV files (a wrapper around dropbox_get specific to csv files) my_data <- db.read.csv(dropbox_credentials, 'my_data.csv', header = TRUE) # Reading .rdata files df <- data.frame(x=1:10, y=rnorm(10)) dropbox_save(dropbox_credentials, df, file="df.rdata") # Now let's download this file back into R rm(df) downloaded_df <- unserialize(dropbox_get(dropbox_credentials, "df.rdata")) # Another quick/dirty way to read private content from your Dropbox into R is using the dropbox_media() function. # Example: source <- dropbox_media(cred, 'test_works/move.txt') read.csv(source$url)
# ext default is .rda. a = 1:4 b = letters[1:3] dropbox_save(dropbox_credentials, list(a,b), "duncan", verbose = TRUE, ext = ".rda")
# Note that all paths are relative to your dropbox root. Leave blank or use / for root. dropbox_move(dropbox_credentials, from_path, to_path) # from_path can be a folder or file. to_path has to be a folder.
# Note that all paths are relative to your dropbox root. Leave blank or use / for root. dropbox_copy(dropbox_credentials, from_path, to_path) # To overwrite existing file/folder in destination, add overwrite = TRUE.
share <- dropbox_share(dropbox_credentials, file) # returns a list of two elements (url and expires) share$url # returns a URL to the share share$expires # shows when the link will expire # File/folder to share. Returns share URL with expiration information. # Link goes directly to files. Folder are automatically zipped up.
Reference: Complete Dropbox API Reference.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.