├── .Rbuildignore ├── .gitignore ├── DESCRIPTION ├── GNUmakefile ├── NAMESPACE ├── R ├── db.wrappers.r ├── dropboxMethods.r ├── dropbox_acc_info.r ├── dropbox_auth.r ├── dropbox_chunked.r ├── dropbox_copy.r ├── dropbox_create_folder.r ├── dropbox_delete.r ├── dropbox_dir.r ├── dropbox_error_handlers.r ├── dropbox_get.r ├── dropbox_load.r ├── dropbox_media.r ├── dropbox_move.r ├── dropbox_put.r ├── dropbox_save.r ├── dropbox_search.r ├── dropbox_serialize.r ├── dropbox_share.r ├── dropbox_unserialize.r ├── errors.R └── startup.r ├── README.md ├── TODO ├── inst └── doc │ └── ArticlePoints ├── man ├── DropboxCredentials-class.Rd ├── db.read.csv.Rd ├── dropbox.file.info.Rd ├── dropbox_acc_info.Rd ├── dropbox_auth.Rd ├── dropbox_copy.Rd ├── dropbox_create_folder.Rd ├── dropbox_delete.Rd ├── dropbox_dir.Rd ├── dropbox_get.Rd ├── dropbox_media.Rd ├── dropbox_move.Rd ├── dropbox_put.Rd ├── dropbox_save.Rd ├── dropbox_search.Rd ├── dropbox_share.Rd ├── exists.in.dropbox.Rd └── sanitize_paths.Rd ├── screenshots ├── create_app.png ├── keys.png └── name_your_app.png └── tests ├── deleteFolder.R ├── dropbox_save.R ├── folderClass.R ├── folderLS.R ├── getCred.R └── serialize.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | new_test.R 2 | screenshots 3 | testing.r 4 | README.md 5 | .gitignore 6 | GNUmakefile 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Ignore/ 2 | testing.R 3 | new_test.R 4 | .Rhistory 5 | .DS_Store 6 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: rDrop 2 | Type: Package 3 | Title: Dropbox R interface. 4 | Version: 0.3-0 5 | License: BSD 6 | Date: 2012-03-14 7 | Authors@R: c(person("Karthik", "Ram", role = c("aut", 8 | "cre"), email = "karthik.ram at gmail.com"), 9 | person("Duncan", "Temple Lang", role = "aut", email = 10 | "duncan at r-project.org")) 11 | Maintainer: Karthik Ram 12 | Description: Programmatic interface to the Dropbox file 13 | system. 14 | URL: http://github.com/karthikram/rDrop 15 | Bug reports: http://github.com/karthikram/rDrop/issues 16 | Depends: 17 | RJSONIO, 18 | RCurl (>= 1.6), 19 | ROAuth (>= 0.92.0), 20 | methods, 21 | plyr, 22 | stringr 23 | Imports: 24 | RJSONIO, 25 | RCurl, 26 | ROAuth, 27 | methods, 28 | plyr, 29 | stringr 30 | Collate: 31 | db.wrappers.r 32 | dropbox_acc_info.r 33 | dropbox_auth.r 34 | dropbox_copy.r 35 | dropbox_create_folder.r 36 | dropbox_delete.r 37 | dropbox_dir.r 38 | dropbox_error_handlers.r 39 | dropbox_get.r 40 | dropbox_media.r 41 | dropbox_move.r 42 | dropbox_put.r 43 | dropbox_save.r 44 | dropbox_search.r 45 | dropbox_share.r 46 | dropbox_load.r 47 | dropbox_serialize.r 48 | dropbox_unserialize.r 49 | startup.r 50 | dropboxMethods.r 51 | errors.R 52 | dropbox_chunked.r 53 | -------------------------------------------------------------------------------- /GNUmakefile: -------------------------------------------------------------------------------- 1 | VERSION=$(shell grep 'Version:' DESCRIPTION | sed -e 's/Version: //') 2 | TAR_FILE=rDrop_$(VERSION).tar.gz 3 | 4 | # code to roxygenize the help pages. 5 | # Why can't roxygen2 be more flexible and 6 | # allow us to control which bits it creates and which bits it 7 | # leaves to us 8 | 9 | ../$(TAR_FILE) build: 10 | (cd .. ; R CMD build rDrop) 11 | 12 | check: build 13 | (cd .. ; R CMD check --as-cran $(TAR_FILE)) 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | import(RCurl) 2 | import(RJSONIO) 3 | import(ROAuth) 4 | import(plyr) 5 | import(stringr) 6 | 7 | 8 | 9 | export(db.read.csv) 10 | export(dropbox.file.info) 11 | export(dropbox_acc_info) 12 | export(dropbox_auth) 13 | export(dropbox_copy) 14 | export(dropbox_create_folder) 15 | export(dropbox_delete) 16 | export(dropbox_dir) 17 | export(dropbox_get) 18 | export(dropbox_media) 19 | export(dropbox_move) 20 | export(dropbox_put) 21 | export(dropbox_save) 22 | export(dropbox_load) 23 | export(dropbox_search) 24 | export(dropbox_share) 25 | export(exists.in.dropbox) 26 | export(sanitize_paths) 27 | export(dropbox_chunked) 28 | exportClasses(DropboxCredentials, DropboxFolder) 29 | 30 | export(DropboxFolder) 31 | exportMethods(DropboxFolder) 32 | 33 | export(dir) 34 | exportMethods(dir) 35 | 36 | 37 | export(dropbox_serialize, dropbox_unserialize) 38 | exportMethods("$", "[[", "[[<-") 39 | export(Dropbox) 40 | -------------------------------------------------------------------------------- /R/db.wrappers.r: -------------------------------------------------------------------------------- 1 | #' Read CSV files stored in Dropbox 2 | #' 3 | #' This function is a simple wrapper around \code{\link{dropbox_get}} for csv files. 4 | #' @param dropbox_credentials Specifies an object of class DropboxCredentials with Dropobox specific credentials. 5 | #' @param file_to_get Specifies the path to the file you want to retrieve. Path must be relative to \code{Dropbox root}. 6 | #' @param ... additional arguments passed on to \code{\link{dropbox_get}} 7 | #' @export 8 | #' @seealso dropbox_get 9 | #' @return data.frame 10 | #' @examples \dontrun{ 11 | #' my_data <- db.read.csv(db_cred, 'data.csv', header = TRUE) 12 | #'} 13 | db.read.csv <- function(dropbox_credentials, file_to_get, ...) { 14 | file <- dropbox_get(dropbox_credentials, file_to_get, ...) 15 | return(unserialize(file)) 16 | } 17 | -------------------------------------------------------------------------------- /R/dropboxMethods.r: -------------------------------------------------------------------------------- 1 | #' @export Dropbox 2 | Dropbox <- 3 | # 4 | # No need for the URIs as these are for acquiring the tokens. 5 | # We assume you already have them. Otherwise use dropbox_oauth 6 | # 7 | function(consumerKey, consumerSecret, 8 | oauthKey, oauthSecret, 9 | signMethod = "HMAC", 10 | .obj = new("DropboxCredentials")) 11 | { 12 | .obj@consumerKey = consumerKey 13 | .obj@consumerSecret = consumerSecret 14 | .obj@oauthKey = oauthKey 15 | .obj@oauthSecret = oauthSecret 16 | 17 | invisible(.obj) 18 | } 19 | 20 | #' @examples { 21 | #' dummy = DropboxFolder("Dummy", drop) 22 | #' } 23 | setGeneric("DropboxFolder", 24 | function(path, consumerKey, consumerSecret, 25 | oauthKey, oauthSecret, 26 | signMethod = "HMAC", ..., 27 | .obj = "DropboxFolder") 28 | { 29 | standardGeneric("DropboxFolder") 30 | }) 31 | 32 | setMethod("DropboxFolder", c("character", "DropboxCredentials"), 33 | function(path, consumerKey, consumerSecret, 34 | oauthKey, oauthSecret, 35 | signMethod = "HMAC", ..., 36 | .obj = "DropboxFolder") 37 | { 38 | if(is.character(.obj)) 39 | .obj = new(.obj, consumerKey) 40 | .obj@path = path 41 | .obj 42 | }) 43 | 44 | 45 | 46 | if(FALSE) { 47 | if(!isGeneric("ls")) 48 | setGeneric("ls", 49 | function (name, pos = -1, envir = as.environment(pos), all.names = FALSE, pattern, ...) 50 | standardGeneric("ls")) 51 | 52 | #XXX This doesn't work. ls() is probably using non-standard evaluation. 53 | setMethod("ls", "ANY", 54 | function (name, pos = -1, envir = as.environment(pos), all.names = FALSE, pattern, ...) { 55 | browser() 56 | base::ls(name) 57 | }) 58 | 59 | setMethod("ls", "DropboxCredentials", 60 | function (name, pos = -1, envir = as.environment(pos), all.names = FALSE, pattern, ...) { 61 | dropbox_dir(name) 62 | }) 63 | } 64 | 65 | 66 | if(!isGeneric("dir")) 67 | setGeneric("dir") 68 | 69 | #XXX This doesn't work. ls() is probably using non-standard evaluation. 70 | 71 | setMethod("dir", "DropboxCredentials", 72 | function (path = ".", pattern = NULL, all.files = FALSE, full.names = FALSE, 73 | recursive = FALSE, ignore.case = FALSE, include.dirs = FALSE) { 74 | dropbox_dir(path) 75 | }) 76 | 77 | 78 | 79 | 80 | 81 | setMethod("$", "DropboxCredentials", 82 | function(x, name) { 83 | id = sprintf("dropbox_%s", name) 84 | 85 | # currently we look in the rDrop package. 86 | # However, we could look along the search path 87 | # and allow for people to extend the set of methods 88 | # However, they can do this by overriding this $ method for their 89 | # own class. 90 | # 91 | ns = getNamespace("rDrop") 92 | if(!exists(id, ns, mode = "function")) 93 | raiseError(c("no method named ", id, " for ", class(x)), "NoMethod") 94 | # We could get the function, but we will leave 95 | # it for now to make the resulting more readable and indicative. 96 | # fun = get(id, ns, mode = "function") 97 | 98 | f = function(...) fun(x, ...) 99 | b = body(f) 100 | b[[1]] = as.name(id) # could inser the actual fun above 101 | body(f) = b 102 | return(f) 103 | 104 | # could create the functions manually if we want special . 105 | switch(name, 106 | delete = function(...) dropbox_delete(x, ...), 107 | get = function(...) dropbox_get(x, ...), 108 | function(...) fun(x, ...) 109 | ) 110 | }) 111 | 112 | 113 | setMethod("[[", c("DropboxCredentials", "character", "missing"), 114 | function(x, i, j, ...) { 115 | dropbox_get(x, i, ...) 116 | }) 117 | 118 | if(FALSE) # path added in method 119 | setMethod("[[", c("DropboxFolder", "character", "missing"), 120 | function(x, i, j, ...) { 121 | dropbox_get(x, sprintf("%s/%s", x@path, i), ...) 122 | }) 123 | 124 | 125 | setMethod("[[<-", c("DropboxCredentials", "character", "missing"), 126 | function(x, i, j, ...) { 127 | dropbox_put(x, i, ...) 128 | }) 129 | 130 | if(FALSE) # path added in method 131 | setMethod("[[<-", c("DropboxFolder", "character", "missing"), 132 | function(x, i, j, ...) { 133 | dropbox_put(x, sprintf("%s/%s", x@path, i), ...) 134 | }) 135 | 136 | 137 | 138 | 139 | setGeneric("getPath", 140 | function(path, url = character(), cred, ...) 141 | standardGeneric("getPath")) 142 | 143 | # A class that indicates that the path has already been expanded with the 144 | # folder information. 145 | setClass("FolderExpandedPath", contains = "character") 146 | 147 | setMethod("getPath", c("FolderExpandedPath"), 148 | function(path, url = character(), cred, ...) { 149 | path 150 | }) 151 | 152 | setMethod("getPath", c("character"), 153 | function(path, url = character(), cred, ...) { 154 | tmp = if (length(path) > 0) { 155 | paste(c(url, path), collapse = "/") # prepend / if url is character() ??? 156 | } else { 157 | if(length(url)) 158 | url 159 | else 160 | "/" # or leave as character() ? 161 | } 162 | new("FolderExpandedPath", tmp) # gsub("//", "/", tmp)) 163 | }) 164 | 165 | setMethod("getPath", c("character", cred = "DropboxFolder"), 166 | function(path, url = character(), cred, ...) 167 | getPath(c(cred@path, path), url)) 168 | 169 | -------------------------------------------------------------------------------- /R/dropbox_acc_info.r: -------------------------------------------------------------------------------- 1 | #'Retrieve Dropbox account summary 2 | #' 3 | #' @param cred An object of class DropboxCredentials with Dropobox specific credentials. 4 | #' @param curl If using in a loop, call getCurlHandle() first and pass 5 | #' the returned value in here (avoids unnecessary footprint) 6 | #' @param ... optional additional curl options (debugging tools mostly). 7 | #' @export dropbox_acc_info 8 | #' @keywords authentication OAuth 9 | #' @seealso related: \code{\link{dropbox_auth}} 10 | #' @return list containing \item{referral link}{Dropbox referral link.} \item{display_name}{Dropbox display name} \item{uid}{Dropbox user id} \item{country}{Dropbox country} \item{quota_info}{Information on shared, quota, and normal.} \item{email}{Dropbox user email} 11 | #' @examples \dontrun{ 12 | #' dropbox_acc_info(db_cred) 13 | #'} 14 | dropbox_acc_info <- 15 | function(cred, curl = getCurlHandle(), ...) { 16 | if (!is(cred, "DropboxCredentials")) 17 | stop("Invalid or missing Dropbox credentials. ?dropbox_auth for more information.", 18 | call. = FALSE) 19 | info <- fromJSON(OAuthRequest(cred, "https://api.dropbox.com/1/account/info", 20 | ..., curl = curl)) 21 | return(info) 22 | } 23 | # API documentation: 24 | # 25 | # 26 | # 27 | # https://www.dropbox.com/developers/reference/api#account-info 28 | -------------------------------------------------------------------------------- /R/dropbox_auth.r: -------------------------------------------------------------------------------- 1 | #' An S4 class that stores Dropbox credentials 2 | #' @name DropboxCredentials-class 3 | #' @rdname DropboxCredentials-class 4 | #' @exportClass DropboxCredentials 5 | setClass("DropboxCredentials", contains = "OAuthCredentials") 6 | 7 | 8 | #' @name DropboxFolder-class 9 | #' @exportClass DropboxFolder 10 | setClass("DropboxFolder", representation(path = "character"), contains = "DropboxCredentials") 11 | 12 | 13 | #' rDrop: programmatic access to Dropbox from R. 14 | #' 15 | #' Before using any of rDrop's functions, you must first create an application on the Dropobox developer site (\url{https://www2.dropbox.com/developers/apps}). This application is specific to you. Follow through with the steps to create your application and copy the generated consumer key/secret combo. Ideally you should save those keys (on separate lines) in your options as: 16 | #' \code{options(DropboxKey = 'Your_App_key')} 17 | #' \code{options(DropboxSecret = 'Your_App_secret')} 18 | #' If you are unable to do so (example: Using \code{rDrop} from a public machine), then you can just specifiy both keys inline. Once you have authenticated, there is no reason to repeat this step for subsequent sessions. Simply save the OAuth object to disk and load it in a script as necessary. Future versions of ROAuth will make it easier for you to just update the token (if necessary) without having to reauthoize via the web. \emph{Do not store these keys in your .rprofile if you are on a public machine}. Anyone with access to this ROAuth object will have full control of your Dropbox account. 19 | #' 20 | #' Once you have created an app, retrieve your access keys using \code{dropbox_auth()} 21 | #' @param cKey A valid Dropbox application key 22 | #' @param cSecret A valid Dropbox application secret 23 | #' @param curl If using in a loop, call getCurlHandle() first and pass 24 | #' the returned value in here (avoids unnecessary footprint) 25 | #' @param ... optional additional curl options (debugging tools mostly). 26 | #' @return Message with success or error. 27 | #' @return Oauth object of class \code{DropboxCredentials} 28 | #' @import RJSONIO ROAuth 29 | #' @export dropbox_auth 30 | #' @aliases rDrop 31 | #' @import stringr 32 | #' @import plyr 33 | #' @import RJSONIO 34 | #' @import ROAuth 35 | #' @import RCurl 36 | #' @examples \dontrun{ 37 | #' dropbox_auth() # if you have keys in .rprofile stored as 38 | #' # options(DropboxKey='YOUR_APP_KEY') 39 | #' # options(DropboxSecret='YOUR_SECRET_KEY') 40 | #' # else use: 41 | #' dropbox_auth('YOUR_APP_KEY', 'YOUR_APP_SECRET') 42 | #' dropbox_tokens <- dropbox_auth() 43 | #' dropbox_token <- dropbox_auth('consumey_key', 'consumer_secret') 44 | #' save(dropbox_token, file = 'dropbox_auth.rdata') 45 | #'} 46 | dropbox_auth <- 47 | function(cKey = getOption("DropboxKey", stop("Missing Dropbox consumer key")), 48 | cSecret = getOption("DropboxSecret", stop("Missing Dropbox app secret")), 49 | curl = getCurlHandle(...), ..., .opts = list(...), .silent = FALSE) 50 | { 51 | 52 | reqURL <- "https://api.dropbox.com/1/oauth/request_token" 53 | authURL <- "https://www.dropbox.com/1/oauth/authorize" 54 | accessURL <- "https://api.dropbox.com/1/oauth/access_token/" 55 | 56 | if(!missing(curl) && length(.opts)) 57 | curlSetOpt(.opts = .opts, curl = curl) 58 | 59 | dropbox_oa <- oauth(cKey, cSecret, reqURL, authURL, accessURL, 60 | obj = new("DropboxCredentials")) 61 | 62 | cred <- handshake(dropbox_oa, 63 | verify = paste("Use the Web browser to grant permission to this code", 64 | "to access Dropbox on your behalf.\nWhen you see 'Success!', hit enter in R", 65 | sep = "\n"), 66 | curl = curl) 67 | 68 | if (!.silent) 69 | cat("\n Dropbox authentication completed successfully.\n") 70 | 71 | return(cred) 72 | } 73 | # API documentation: 74 | 75 | # https://www.dropbox.com/developers/reference/api#request-token 76 | -------------------------------------------------------------------------------- /R/dropbox_chunked.r: -------------------------------------------------------------------------------- 1 | #' Upload large content in chunks 2 | #' 3 | #' Use this function to upload very large files or content which exceeds the 150Mb 4 | #' maximum size for dropbox_put. This allows us to upload the content in chunks 5 | #' each of which can be up to 150Mb but which combined are much larger. 6 | #' This also allows us to resume uploads. 7 | #' @param cred An object of class DropboxCredentials with Dropobox specific credentials. 8 | #' @param what the content to upload, which is either the name of a file, in-memory text or a raw vector. 9 | #' @param filename the name of the file to create in the Dropbox folder. 10 | #' @param chunkSize the number of bytes to send in each chunk. The default is 4Mb. 11 | #' @param range allows the caller to specify a range of bytes rather than uploading the entire content. 12 | #' @param curl If using in a loop, call getCurlHandle() first and pass 13 | #' the returned value in here (avoids unnecessary footprint) 14 | #' @param ... optional additional curl options (debugging tools mostly). 15 | #' @param .silent a logical value that controls whether progress information is displayed on the console. 16 | #' @param contentType the string describing the content type. 17 | #' @return 18 | #' @seealso \code{\link{dropbox_put}} 19 | dropbox_chunked <- 20 | function(cred, what, filename = basename(what), chunkSize = 4*10^6, 21 | range = c(1, NA), ..., curl = getCurlHandle(), .silent = FALSE, 22 | contentType = "application/octet-stream") 23 | { 24 | # source of data can be raw vectors, files and connections 25 | if(is.character(what)) { 26 | input = file(what, "rb") 27 | on.exit(close(input)) 28 | totalSize = file.info(what)[1, "size"] 29 | } else if(is.raw(what)) { 30 | # raw buffer or a connection 31 | input = rawConnection(what, "r") 32 | on.exit(close(input)) 33 | totalSize = length(input) 34 | } else if(is(what, "connection")) { 35 | input = what 36 | totalSize = NA 37 | } 38 | 39 | if(!is.na(range[1]) && range[1] > 1) { 40 | readBin(input, raw(), range[1]) 41 | } 42 | 43 | if(!is.na(range[2])) 44 | totalSize = range[2] 45 | 46 | targetURL = "https://api-content.dropbox.com/1/chunked_upload" 47 | 48 | # Need to reset the Content-Length, etc. in the final request 49 | # so just clone the handle now. 50 | dupCurl = dupCurlHandle(curl) 51 | 52 | # Send the first block to obtain the upload_id token 53 | block = readBin(input, raw(), chunkSize) 54 | ans = OAuthRequest(cred, targetURL, , "PUT", upload = TRUE, 55 | readfunction = block, infilesize = length(block), 56 | httpheader = c('Content-Type' = contentType), 57 | ..., curl = curl) 58 | 59 | tmp = fromJSON(ans) 60 | offset = length(block) # + 1 61 | id = tmp[["upload_id"]] 62 | ctr = 2 63 | 64 | while(is.na(totalSize) || offset < totalSize) { 65 | tmp.url = sprintf("%s?upload_id=%s&offset=%d", targetURL, id, offset) 66 | block = readBin(input, raw(), chunkSize) 67 | nbytes = length(block) 68 | if(!.silent) { 69 | cat(ctr, "sending", nbytes, "bytes\n") 70 | ctr = ctr + 1 71 | } 72 | 73 | # There is a problem with the signature on this request. 74 | # Potential issue is the upload_id and offset arguments 75 | # are in the URL but not in the request 76 | # We may need to sign it as if they are parameters, but 77 | # then put the parameters in the URL. ROAuth currently 78 | # doesn't have a mechanism to specify this. 79 | # Added in my version via .sendURL. 80 | tmp = OAuthRequest(cred, 81 | targetURL, c(upload_id = id, offset = offset), 82 | "PUT", upload = TRUE, 83 | httpheader = c('Content-Type' = contentType), 84 | readfunction = block, infilesize = nbytes, 85 | ..., curl = curl, 86 | .sendURL = tmp.url) 87 | tmp = fromJSON(tmp) 88 | if("error" %in% names(tmp)) 89 | stop("problem uploading chunk: ", tmp[["error"]]) 90 | 91 | offset = offset + nbytes 92 | } 93 | 94 | cat("committing upload to the file\n") 95 | url = rDrop:::getPath(filename, "https://api-content.dropbox.com/1/commit_chunked_upload/dropbox", cred) 96 | 97 | fromJSON(OAuthRequest(cred, url, list(overwrite = "true", upload_id = id), 98 | "POST", ..., curl = dupCurl)) 99 | 100 | } 101 | -------------------------------------------------------------------------------- /R/dropbox_copy.r: -------------------------------------------------------------------------------- 1 | #' Function to copy files or folder within Dropbox. 2 | #' 3 | #' Use this function to copy files or folders within your Dropbox. Destination must be a folder otherwise the function will return an error. 4 | #' @param cred An object of class DropboxCredentials with Dropobox specific credentials. 5 | #' @param from_path Path to file or folder to be copied, relative to dropbox root. 6 | #' @param to_path Path to destination, including the new name for the file or folder, relative to dropbox root. This can also be a \code{DropboxFolder} in which case the name of the \code{from_path} file is used as the target file name in the destination folder. 7 | #' @keywords file_copy 8 | #' @seealso dropbox_move dropbox_create_folder 9 | #' @param curl If using in a loop, call getCurlHandle() first and pass 10 | #' the returned value in here (avoids unnecessary footprint) 11 | #' @param ... optional additional curl options (debugging tools mostly).. 12 | #' @return Message with success or error. 13 | #' @seealso related: \code{\link{dropbox_move}} 14 | #' @aliases dropbox_cp 15 | #' @export dropbox_copy 16 | #' @examples \dontrun{ 17 | #' dropbox_copy(cred, 'copy.txt', 'Public') 18 | #' 19 | #'} 20 | dropbox_copy <- 21 | function(cred, from_path = NULL, to_path = NULL, 22 | curl = getCurlHandle(), ..., .checkIfExists = TRUE, .silent = FALSE) 23 | { 24 | if (!is(cred, "DropboxCredentials")) 25 | stop("Invalid or missing Dropbox credentials. ?dropbox_auth for more information.", 26 | call. = FALSE) 27 | if (is.null(from_path)) { 28 | stop("Did not specify full path for source", call. = F) 29 | } 30 | 31 | if(is(to_path, "DropboxFolder")) { 32 | to_path = sprintf("%s/%s", to_path@path, basename(getPath(from_path, cred = cred))) 33 | } 34 | 35 | 36 | check_paths <- sanitize_paths(from_path, to_path, cred) 37 | from_path <- check_paths[[1]] 38 | to_path <- check_paths[[2]] 39 | 40 | if (!exists.in.dropbox(cred, from_path, ..., curl = getCurlHandle())) 41 | raiseError(c("Source file or folder ", from_path, " does not exist"), 42 | "NonExistantFile") 43 | 44 | if (.checkIfExists && !exists.in.dropbox(cred, dirname(to_path), is_dir = TRUE, 45 | ..., curl = getCurlHandle())) 46 | raiseError(c("Destination ", dirname(to_path), " is not a valid folder"), c("InvalidFolder", "NonExistantFile")) 47 | 48 | if (grepl("\\.", to_path)) { 49 | if (.checkIfExists && exists.in.dropbox(cred, to_path, ..., curl = getCurlHandle())) 50 | raiseError(c("File ", to_path, " already exists in destination"), "TargetFileExists") 51 | } 52 | 53 | copy <- fromJSON(OAuthRequest(cred, "https://api.dropbox.com/1/fileops/copy", 54 | list(root = "dropbox", from_path = from_path, to_path = to_path), 55 | , "POST", ..., curl = curl)) 56 | if (is.character(copy)) { 57 | stop(copy[[1]], call. = FALSE) 58 | } 59 | if (is.list(copy) && !.silent) { 60 | cat(from_path, "succcessfully copied to", copy$path, "on", 61 | copy$modified, "\n") 62 | } 63 | } 64 | # API documentation: # 65 | # 66 | # https://www.dropbox.com/developers/reference/api#fileops-copy 67 | -------------------------------------------------------------------------------- /R/dropbox_create_folder.r: -------------------------------------------------------------------------------- 1 | #'Function to create new folders in Dropbox. 2 | #' 3 | #' @param cred An object of class DropboxCredentials with Dropobox specific credentials. 4 | #' @param folder_name Specifies the path to the new folder to create relative to root. 5 | #' @return a DropboxFolder object representing the path to the folder, along wit the credentials to interact with it. 6 | #' @param curl If using in a loop, call getCurlHandle() first and pass 7 | #' the returned value in here (avoids unnecessary footprint) 8 | #' @param ... optional additional curl options (debugging tools mostly). 9 | #' @import stringr 10 | #' @import plyr 11 | #' @export dropbox_create_folder 12 | #' @examples \dontrun{ 13 | #' dropbox_create_folder(db_cred, 'new_folder') 14 | #'} 15 | dropbox_create_folder <- 16 | function(cred, folder_name = NULL, curl = getCurlHandle(), .silent = FALSE, ...) 17 | { 18 | if (!is(cred, "DropboxCredentials")) 19 | stop("Invalid or missing Dropbox credentials. ?dropbox_auth for more information.", 20 | call. = FALSE) 21 | 22 | if (is.null(folder_name)) { 23 | stop("You did not specify a folder name", call. = FALSE) 24 | } 25 | # assuming someone wants to create this inside a sub-folder 26 | # and not the dropbox root 27 | if (grepl("^/", folder_name)) { 28 | folder_name <- str_sub(folder_name, start = 2) 29 | } 30 | if (grepl("/$", folder_name)) { 31 | folder_name <- str_sub(folder_name, end = str_length(folder_name) - 32 | 1) 33 | } 34 | 35 | folder_name = getPath(folder_name, cred = cred) 36 | # Check for duplicates. 37 | if ((exists.in.dropbox(cred, folder_name, is_dir = TRUE, ..., 38 | curl = getCurlHandle()))) { 39 | stop("Folder already exists", call. = FALSE) 40 | } 41 | # Now create the folder. 42 | dir_metadata <- fromJSON(OAuthRequest(cred, "https://api.dropbox.com/1/fileops/create_folder/", 43 | list(root = "dropbox", path = folder_name), ..., curl = curl)) 44 | 45 | # XXX do we need to do this, i.e. add the dropbox. Perhaps just use folder_name now that it is expanded. 46 | location <- paste(dir_metadata$root, dir_metadata$path, sep = "") 47 | if(!.silent) 48 | cat("Folder successfully created at", location, "on", dir_metadata$modified, "\n") 49 | 50 | invisible(new("DropboxFolder", cred, path = location)) 51 | } 52 | # API documentation: 53 | # 54 | # 55 | # 56 | # 57 | # https://www.dropbox.com/developers/reference/api#fileops-create-folder 58 | -------------------------------------------------------------------------------- /R/dropbox_delete.r: -------------------------------------------------------------------------------- 1 | #'Function to delete a file or folder from Dropbox 2 | #' 3 | #' Function will delete specified object in Dropbox (assuming it exists). To skip deletion conformation, set ask = FALSE in function call. Accidentally deleted objects may be recovered using Dropbox's restore feature. 4 | #' @param cred An object of class DropboxCredentials with Dropobox specific credentials. 5 | #' @param file_to_delete Specifies the path to the file or folder to be deleted. 6 | #' @param curl If using in a loop, call getCurlHandle() first and pass 7 | #' the returned value in here (avoids unnecessary footprint) 8 | #' @param ... optional additional curl options (debugging tools mostly). 9 | #' @param ask logical set to TRUE. If set to false, function will not confirm delete operation 10 | #' @return Nothing. A message upon successful deletion. 11 | #' @export dropbox_delete 12 | #' @examples \dontrun{ 13 | #' dropbox_delete(dropbox_credential, 'path/to/file') 14 | #'} 15 | dropbox_delete <- 16 | function(cred, file_to_delete = NULL, ask = interactive(), 17 | curl = getCurlHandle(), ..., .checkIfExists = TRUE, .silent = FALSE) 18 | { 19 | verify <- "" 20 | if (!is(cred, "DropboxCredentials")) 21 | stop("Invalid or missing Dropbox credentials. ?dropbox_auth for more information.", call.= FALSE) 22 | 23 | file_to_delete = getPath(file_to_delete, cred = cred) 24 | 25 | if(.checkIfExists && !exists.in.dropbox(cred, file_to_delete, ..., curl = getCurlHandle())) 26 | stop("File or folder not found", call. = FALSE) 27 | 28 | 29 | if(ask) { 30 | verify <- readline(paste("Are you sure you want to delete", 31 | file_to_delete, " (Y/N)? ")) 32 | verify <- toupper(verify) 33 | if(verify != "Y" & verify != "N") { 34 | stop("Unexpected response. \n", call. = F) 35 | } 36 | } 37 | if (verify == "Y" || !ask) { 38 | deleted <- fromJSON(OAuthRequest(cred, "https://api.dropbox.com/1/fileops/delete", 39 | list(root="auto", path = file_to_delete)), 40 | ..., curl = curl) 41 | if(!.silent && is.list(deleted)) { 42 | cat(deleted$path, "was successfully deleted on", deleted$modified, "\n") 43 | } 44 | } 45 | TRUE 46 | } 47 | # API documentation: 48 | # 49 | # 50 | # 51 | # 52 | # https://www.dropbox.com/developers/reference/api#fileops-delete 53 | 54 | -------------------------------------------------------------------------------- /R/dropbox_dir.r: -------------------------------------------------------------------------------- 1 | #'Function to list contents of a Dropbox folder. 2 | #' 3 | #' If no folder is specified, it will only list contents of the root folder. 4 | #' @param cred An object of class DropboxCredentials with Dropobox specific credentials. 5 | #' @param path The directory to list. Not yet implemented 6 | #' @param verbose logical. FALSE returns a list with file names in root folder. TRUE returns a \code{data.frame} with the following fields: id, revision, rev, thumb_exists, bytes, path, modified, and is_dir 7 | #' @param deleted logical. Default is FALSE. Set to TRUE to also list deleted files. 8 | #' @param pattern an optional regular expression. Only file names which match the regular expression will be returned. 9 | #' @param curl If using in a loop, call getCurlHandle() first and pass 10 | #' the returned value in here (avoids unnecessary footprint) 11 | #' @param ... optional additional curl options (debugging tools mostly). 12 | #' @return directory listing with file or folder names unless \code{verbose = TRUE} in which case a data.frame is returned. 13 | #' @export dropbox_dir 14 | #' @examples \dontrun{ 15 | #' dropbox_dir(db_cred) 16 | #' dropbox_dir(db_cred, path='/specific_folder') 17 | #' dropbox_dir(db_cred,path='/specific_folder', verbose = TRUE) 18 | #' dropbox_dir(db_cred,path='/specific_folder', pattern='file', verbose = TRUE) 19 | #' returns a dataframe with fields .id, revision, rev, thumb_exists, bytes, modified path, is_dir, icon, root, size, client_mtime, mimetype. 20 | #'} 21 | dropbox_dir <- 22 | function(cred, path = character(), verbose = FALSE, 23 | deleted = FALSE, pattern = NULL, curl = getCurlHandle(), ..., .checkIfExists = TRUE) 24 | { 25 | if (!is(cred, "DropboxCredentials")) 26 | stop("Invalid or missing Dropbox credentials. ?dropbox_auth for more information.", 27 | call. = FALSE) 28 | 29 | url <- "https://api.dropbox.com/1/metadata/auto" 30 | if (length(path) && .checkIfExists && 31 | !exists.in.dropbox(cred, path, is_dir = TRUE, ..., curl = getCurlHandle())) 32 | stop("There is no such folder in your Dropbox", call. = FALSE) 33 | 34 | if (length(path) && grepl("/$", path)) { 35 | path <- str_sub(path, end = str_length(path) - 1) 36 | } 37 | 38 | url = getPath(path, url = url, cred = cred) 39 | 40 | metadata <- fromJSON(OAuthRequest(cred, url, list(include_deleted = deleted), 41 | ..., curl = curl)) 42 | 43 | names(metadata$contents) <- basename(sapply(metadata$contents, 44 | `[[`, "path")) 45 | 46 | file_sys <- ldply(metadata$contents, data.frame) 47 | if (!is.null(pattern)) { 48 | matches <- str_detect(file_sys$.id, pattern) 49 | file_sys <- file_sys[matches, ] 50 | } 51 | if (!verbose) { 52 | return(file_sys$.id) 53 | } else { 54 | return(file_sys) 55 | } 56 | } 57 | # API documentation: 58 | # https://www.dropbox.com/developers/reference/api#metadata 59 | # Issues: Fails with empty directories 60 | # filename, revision, thumb, bytes, modified, path, and is_dir 61 | -------------------------------------------------------------------------------- /R/dropbox_error_handlers.r: -------------------------------------------------------------------------------- 1 | #' Check to see if an object exists in Dropbox 2 | #' 3 | #' This function is meant for internal use especially when copying or moving files. 4 | #' @param cred An object of class DropboxCredentials with Dropobox specific credentials. 5 | #' @param path Path to object 6 | #' @param is_dir if set to TRUE, will only look for folders. Otherwise will return file or folder. 7 | #' @param curl If using in a loop, call getCurlHandle() first and pass 8 | #' @param ... optional additional curl options (debugging tools mostly). 9 | #' @export 10 | #' @return logical. TRUE/FALSE 11 | #' @examples \dontrun{ 12 | #' exists.in.dropbox(cred,'test_folder') 13 | #' exists.in.dropbox(cred,'test_folder',is_dir='dir') 14 | #'} 15 | exists.in.dropbox <- 16 | function(cred, path = NULL, is_dir = NULL, ..., curl = getCurlHandle()) 17 | { 18 | if (!is(cred, "DropboxCredentials")) 19 | stop("Invalid or missing Dropbox credentials. ?dropbox_auth for more information.") 20 | # default response so function can proceed. 21 | response <- TRUE 22 | if (is.null(path)) { 23 | stop("You did not specify an object to verify", call. = FALSE) 24 | } 25 | # First search Dropbox to see if the object exists 26 | full_path <- path 27 | if (full_path == "/") { 28 | response <- TRUE 29 | } else { 30 | # If leading slash is missing, add it. 31 | if (!grepl("^/", full_path)) { 32 | full_path <- paste("/", full_path, sep = "") 33 | } 34 | # Remove trailing slash 35 | if (grepl("/$", full_path)) { 36 | full_path <- str_sub(full_path, end = str_length(full_path) - 37 | 1) 38 | } 39 | query <- basename(path) 40 | res <- dropbox_search(cred, query, ..., curl = curl) 41 | if (is.null(res)) { 42 | response <- FALSE 43 | } 44 | if (empty(res)) { 45 | response <- FALSE 46 | } 47 | # OK, object exists, but let's see if there was more than 48 | # one result 49 | if (!identical(query, full_path)) { 50 | res <- res[which(res$path == full_path), ] 51 | if (dim(res)[1] != 1) { 52 | response <- FALSE 53 | } 54 | } 55 | # OK, only one result returned. 56 | if (response) { 57 | if (!is.null(is_dir)) { 58 | if (is_dir) { 59 | response <- ifelse(res$is_dir, TRUE, FALSE) 60 | } 61 | if (!is_dir) { 62 | response <- ifelse(!res$is_dir, TRUE, FALSE) 63 | } 64 | } 65 | } 66 | } # end the else 67 | return(response) 68 | } 69 | #'Return file attributes for a specified file supplied in the path argument. 70 | #' 71 | #' @param cred An object of class DropboxCredentials with Dropobox specific credentials. 72 | #' @param path_to_file Path to file relative to Dropbox root. 73 | #' @seealso \code{link{is.dropbox.file}} 74 | #' @return list 75 | #' @export dropbox.file.info 76 | #' @examples \dontrun{ 77 | #' dropbox.file.inco(cred, '/folder/file.txt') 78 | #'} 79 | dropbox.file.info <- 80 | function(cred, path_to_file) { 81 | # Add leading slash in case it is missing 82 | if (!grepl("^/", path_to_file)) { 83 | path_to_file <- paste("/", path_to_file, sep = "") 84 | } 85 | dfile <- dropbox_search(cred, path_to_file) 86 | dfile # Return a list containing filename, filetype, date 87 | # modified, and revision number. 88 | } 89 | #' Verify paths for copy and move operations 90 | #' 91 | #' Function is meant for internal use in \code{\link{dropbox_move}} and \code{\link{dropbox_copy}} 92 | #' @param from_path source path 93 | #' @param to_path destination path. Leave blank for dropbox root. 94 | #' @return list with clean paths 95 | #' @export sanitize_paths 96 | #' @examples \dontrun{ 97 | #' santize_paths(from_path, to_path) 98 | #'} 99 | sanitize_paths <- 100 | function(from_path, to_path = NULL, cred = NULL) 101 | { 102 | if (is.null(to_path)) 103 | to_path <- "/" 104 | if (!grepl("^/", from_path)) 105 | from_path <- paste("/", from_path, sep = "") 106 | if (grepl("/$", from_path)) 107 | from_path <- str_sub(from_path, end = -1) 108 | if (!grepl("^/", to_path)) 109 | to_path <- paste("/", to_path, sep = "") 110 | # browser() 111 | if (dirname(to_path) == "/" && basename(to_path) == "") 112 | to_path <- paste("/", basename(from_path), sep = "") 113 | if (dirname(to_path) == "/" && basename(to_path) != "") 114 | to_path <- paste("/", basename(to_path), sep = "") 115 | if (nchar(to_path) > 1 && !grepl("\\.", to_path)) 116 | to_path <- paste(to_path, "/", basename(from_path), sep = "") 117 | # cat('from: ', from_path, '\n to: ', to_path) 118 | 119 | ans <- list(from_path, to_path) 120 | 121 | if(length(cred)) 122 | lapply(ans, function(x) getPath(x, cred = cred)) 123 | else 124 | ans 125 | } 126 | -------------------------------------------------------------------------------- /R/dropbox_get.r: -------------------------------------------------------------------------------- 1 | #'Downloads a file from your Dropbox 2 | #' 3 | #' Currently the function does not provide much support other than retrieving the contents of whatever Dropbox file you specify. Use \code{TextConnection} to process ascii files for the time being. 4 | #' @param cred Specifies an object of class DropboxCredentials with Dropobox specific credentials. 5 | #' @param file_to_get Specifies the path to the file you want to retrieve. Path must be relative to \code{Dropbox root}. 6 | #' @param curl If using in a loop, call getCurlHandle() first and pass 7 | #' the returned value in here (avoids unnecessary footprint). 8 | #' @param binary set if the object you are retrieving is binary content. 9 | #' @param ... optional additional curl options (debugging tools mostly).. 10 | #' @param root the name of the root folder 11 | #' @return R object 12 | #' @export dropbox_get 13 | #' @examples \dontrun{ 14 | #' x <- dropbox_get(db_cred, '/folder/file.csv') 15 | #'} 16 | dropbox_get <- 17 | function(cred, file_to_get, curl = getCurlHandle(), ..., binary = NA, 18 | root = "dropbox", .checkIfExists = TRUE) 19 | { 20 | if (!is(cred, "DropboxCredentials") || missing(cred)) 21 | missingCredentialsError() 22 | 23 | file_to_get = getPath(file_to_get, cred = cred) # paste(file_to_get, collapse = "/") 24 | 25 | if (.checkIfExists && !(exists.in.dropbox(cred, path = file_to_get, is_dir = FALSE,..., curl = curl))) { 26 | stop("File or folder does not exist", call. = FALSE) 27 | } 28 | 29 | invisible(suppressWarnings(OAuthRequest(cred, "https://api-content.dropbox.com/1/files/", 30 | list(root = root, path = file_to_get), "GET", 31 | binary = binary, ..., curl = curl))) 32 | } 33 | # API documentation: 34 | # 35 | # 36 | # 37 | # https://www.dropbox.com/developers/reference/api#files-GET 38 | -------------------------------------------------------------------------------- /R/dropbox_load.r: -------------------------------------------------------------------------------- 1 | #' Function to load an RDA file from Dropbox. 2 | 3 | #' @param cred Specifies an object of class DropboxCredentials with Dropobox specific credentials. 4 | #' @param file the name of the file in the Dropbox folder 5 | #' @param envir the environment in which to load the variables in the file. See the 6 | #' regular \code{\link{load}} function. 7 | #' @return a character vector containing the names of the new variables created. This is the return value from a call to \code{\link{load}}. 8 | #' @export 9 | dropbox_load <- 10 | function(cred, file, envir = parent.frame(), ..., .checkIfExists = TRUE) 11 | { 12 | data = dropbox_get(cred, file, binary = TRUE, ..., .checkIfExists = .checkIfExists) 13 | con = rawConnection(data) 14 | load(con, envir) 15 | } 16 | -------------------------------------------------------------------------------- /R/dropbox_media.r: -------------------------------------------------------------------------------- 1 | #' Stream data from Dropbox 2 | #' 3 | #' This function behaves very similar to \code{dropbox_share}. The difference is that this bypasses the Dropbox webserver, used to provide a preview of the file, so that you can effectively stream the contents of your media. 4 | #' @param cred Specifies an object of class DropboxCredentials with Dropobox specific credentials. 5 | #' @param path Path to object on Dropbox. 6 | #' @param curl If using in a loop, call getCurlHandle() first and pass 7 | #' the returned value in here (avoids unnecessary footprint) 8 | #' @param ... optional additional curl options (debugging tools mostly). 9 | #' @seealso \code{\link{dropbox_share}} 10 | #' @return list with URL to R object and expiration date/time. 11 | #' @export dropbox_media 12 | #' @examples \dontrun{ 13 | #' dropbox_media(db_cred, '/data/file.csv') 14 | #'} 15 | dropbox_media <- 16 | function(cred, path = NULL, curl = getCurlHandle(), ..., .checkIfExists = TRUE) { 17 | if (!is(cred, "DropboxCredentials")) 18 | stop("Invalid or missing Dropbox credentials. ?dropbox_auth for more information.", 19 | call. = FALSE) 20 | if (.checkIfExists && !(exists.in.dropbox(cred, path = path, ..., curl = getCurlHandle()))) { 21 | stop("Content does not exist in dropbox", call. = FALSE) 22 | } 23 | if (!is.null(path)) { 24 | url <- paste("https://api.dropbox.com/1/media/dropbox/", 25 | path, sep = "") 26 | } 27 | media <- fromJSON(OAuthRequest(cred, url), ..., curl = curl) 28 | return(as.list(media)) 29 | } 30 | # API Documentation: 31 | # https://www.dropbox.com/developers/reference/api#media 32 | -------------------------------------------------------------------------------- /R/dropbox_move.r: -------------------------------------------------------------------------------- 1 | #' Move files within Dropbox 2 | #' 3 | #' Allows users to move files or folders inside the dropbox storage. 4 | #' @param cred Specifies an object of class DropboxCredentials with Dropobox specific credentials. 5 | #' @param from_path Path to file or folder to be copied, relative to root. 6 | #' @param to_path Path to destination, including the new name for the file or folder, relative to root. 7 | #' @param curl If using in a loop, call getCurlHandle() first and pass 8 | #' the returned value in here (avoids unnecessary footprint) 9 | #' @param ... optional additional curl options (debugging tools mostly). 10 | #' @seealso dropbox_copy dropbox_create_folder 11 | #' @param verbose default is FALSE. Set to true to receive full outcome. 12 | #' @seealso related: \code{\link{dropbox_copy}} 13 | #' @return Message on successful completion or error. 14 | #' @aliases dropbox_mv 15 | #' @export dropbox_move 16 | #' @examples \dontrun{ 17 | #' dropbox_move(cred, 'move.txt','test_works') 18 | #' File succcessfully moved to /test_works/move.txt on Thu, 29 Mar 2012 20:41:45 +0000 19 | #'} 20 | dropbox_move <- 21 | function(cred, from_path = NULL, to_path = NULL, 22 | verbose = FALSE, curl = getCurlHandle(), ..., .checkIfExists = TRUE) 23 | { 24 | if (!is(cred, "DropboxCredentials")) 25 | stop("Invalid or missing Dropbox credentials. ?dropbox_auth for more information.", 26 | call. = FALSE) 27 | # Note: to_path needs a leading / because root is 'dropbox' 28 | if (is.null(from_path)) { 29 | stop("Did not specify full path for source", call. = F) 30 | } 31 | 32 | if(is(to_path, "DropboxFolder")) 33 | to_path = sprintf("%s/%s", to_path@path, basename(getPath(from_path, cred = cred))) 34 | 35 | check_paths <- sanitize_paths(from_path, to_path, cred) 36 | from_path <- check_paths[[1]] 37 | to_path <- check_paths[[2]] 38 | if (.checkIfExists && !exists.in.dropbox(cred, from_path, ..., curl = getCurlHandle())) 39 | stop("Source file or folder does not exist", call. = FALSE) 40 | if (.checkIfExists && !exists.in.dropbox(cred, dirname(to_path), is_dir = TRUE, 41 | ..., curl = getCurlHandle())) 42 | stop("Destination is not a valid folder", call. = FALSE) 43 | 44 | if (grepl("\\.", to_path)) { 45 | if (.checkIfExists && exists.in.dropbox(cred, to_path, ..., curl = getCurlHandle())) 46 | stop("File already exists in destination", call. = FALSE) 47 | } 48 | move <- fromJSON(OAuthRequest(cred, "https://api.dropbox.com/1/fileops/move", 49 | list(root = "dropbox", from_path = from_path, to_path = to_path), 50 | "POST", ..., curl = curl)) 51 | if (is.character(move)) { 52 | stop(move[[1]], call. = FALSE) 53 | } 54 | if (verbose) { 55 | return(move) 56 | } else { 57 | if (is.list(move)) { 58 | cat("File succcessfully moved to", move$path, "on", move$modified, 59 | "\n") 60 | } 61 | } 62 | } 63 | # API documentation: 64 | # 65 | # 66 | # 67 | # https://www.dropbox.com/developers/reference/api#fileops-move 68 | -------------------------------------------------------------------------------- /R/dropbox_put.r: -------------------------------------------------------------------------------- 1 | #' Function to upload content (in-memory or a file) to Dropbox. 2 | 3 | #' @param cred Specifies an object of class DropboxCredentials with Dropobox-specific credentials. 4 | #' @param what the content to upload, which is either the name of a file, in-memory text or a raw vector. 5 | #' @param filename the name of the file to create in the Dropbox folder. 6 | #' @param curl If using in a loop, call getCurlHandle() first and pass 7 | #' the returned value in here (avoids unnecessary footprint) 8 | #' @param ... optional additional curl options (debugging tools mostly). 9 | #' @param verbose default is FALSE. Set to true to receive full outcome. 10 | #' @param contentType the string describing the content type. 11 | #' @return information about the uploaded file on dropbox. 12 | #' @examples \dontrun{ 13 | #' dropbox_put(auth, I("This is in-memory text"), "inMemory.txt") 14 | #' 15 | #' dropbox_put(auth, "DESCRIPTION", "rDrop_DESCRIPTION") 16 | #' print(dropbox_get(auth, "rDrop_DESCRIPTION")) 17 | #' } 18 | dropbox_put <- 19 | function(cred, what, filename = what, curl = getCurlHandle(), ..., verbose = FALSE, 20 | contentType = "application/octet-stream") 21 | { 22 | filename = paste(filename, collapse = "/") 23 | url <- sprintf("https://api-content.dropbox.com/1/files_put/dropbox/%s", filename) 24 | 25 | #XXX what about raw? 26 | size = if(is(what, "AsIs")) { 27 | if(is.character(what)) 28 | sum(nchar(what)) 29 | else 30 | length(what) 31 | } else 32 | file.info(what)[1, "size"] 33 | 34 | if(size > 1048576 * 150) 35 | return(dropbox_chunked(cred, what, filename, curl = curl, .silent = !verbose)) 36 | 37 | input <- RCurl:::uploadFunctionHandler(what) 38 | 39 | drop_save <- fromJSON(OAuthRequest(cred, url, , "PUT", upload = TRUE, 40 | readfunction = input, infilesize = size, 41 | httpheader = c(`Content-Type` = contentType), 42 | ..., curl = curl)) 43 | 44 | if (verbose && is.list(drop_save)) { 45 | message("File succcessfully drop_saved to", drop_save$path, 46 | "on", drop_save$modified) 47 | } 48 | 49 | drop_save 50 | } 51 | 52 | readBinary = 53 | function(filename) 54 | { 55 | readBin(filename, raw(), n = file.info(filename)[1, "size"]) 56 | } 57 | -------------------------------------------------------------------------------- /R/dropbox_save.r: -------------------------------------------------------------------------------- 1 | #' Function to save an object from R into Dropbox 2 | #' 3 | #' This function saves an R object to Dropbox. One can then retrieve it and load 4 | #' it back into R. 5 | #' @param cred Specifies an object of class DropboxCredentials with Dropobox specific credentials. 6 | #' @param list List of objects from the current R environment that needs to be saved into dropbox 7 | #' @param file Required filename. No extenstion needs to be supplied. If you provide one, it will be stripped and replace with rda. 8 | #' @param envir optional. Defaults to parent environment. 9 | #' @param precheck internal use. Checks to make sure all objects are in the parent environment. 10 | #' @param curl If using in a loop, call getCurlHandle() first and pass 11 | #' the returned value in here (avoids unnecessary footprint) 12 | #' @param verbose default is FALSE. Set to true to receive full outcome. 13 | #' @param ... optional additional curl options (debugging tools mostly). 14 | #' @param ext file extension. Default is \code{.rda} 15 | #' @export 16 | #' @return JSON object 17 | #' @examples \dontrun{ 18 | #' dropbox_save(cred, robject, file='filename') 19 | #' dropbox_save(cred, file = 'testRData', .objs = list(a = 1:3, b = letters[1:10])) 20 | #' a = dropbox_get(cred, 'testRData.rdata', binary = TRUE) 21 | #' val = unserialize(rawConnection(a)) 22 | #' 23 | #' # specifying our own name without the standard .rdata 24 | #' dropbox_save(cred, list(a = 1:4, b = letters[1:3]), I('duncan.rda'), verbose = TRUE) 25 | #' # or 26 | #' dropbox_save(cred, list(a = 1:4, b = letters[1:3]), 'duncan', verbose = TRUE, ext = '.rda') 27 | #'} 28 | dropbox_save <- 29 | function(cred, ..., list = character(), file = stop("'file' must be specified"), 30 | envir = parent.frame(), precheck = TRUE, verbose = FALSE, curl = getCurlHandle(), 31 | ext = ".rda", .opts = list()) 32 | { 33 | 34 | #XXX shouldn't this end up being a call to dropbox_put(). 35 | 36 | if (!is(cred, "DropboxCredentials")) 37 | stop("Invalid or missing Dropbox credentials. ?dropbox_auth for more information.", 38 | call. = FALSE) 39 | # I suggest we discard this approach. The caller specifies 40 | # dropbox_save(cred, list(x, y, z)). It is up to the caller 41 | # to specify names for the list. 42 | # We could use ... and then use the names from that. 43 | # We can use a ..., list = character() approach as in rm() 44 | # but is not needed or really sane. It is non-standard evaluation. 45 | # Recently added: 46 | # But it is consistent with save() so probably best to follow that. See the call to save() below. 47 | #Karthik: OK. 48 | if (FALSE && missing(.objs)) { 49 | names <- as.character(substitute(list(...)))[-1L] 50 | list <- c(list, names) 51 | if (precheck) { 52 | ok <- unlist(lapply(list, exists, envir = envir)) 53 | if (!all(ok)) { 54 | n <- sum(!ok) 55 | stop(sprintf(ngettext(n, "object %s not found", "objects %s not found"), 56 | paste(sQuote(list[!ok]), collapse = ", ")), domain = NA) 57 | } 58 | } 59 | .objs <- structure(lapply(list, get, envir), names = list) 60 | } 61 | if (is.character(file) && !nzchar(file)) 62 | stop("'file' must be non-empty string") 63 | # Allow the caller to force a particular name. 64 | filename <- if (!is(file, "AsIs") && !grepl(sprintf("%s$", ext), file)) 65 | paste(str_trim(str_extract(file, "[^.]*")), ext, sep = "") 66 | else 67 | file 68 | #XXX call getPath() 69 | url <- sprintf("https://api-content.dropbox.com/1/files_put/dropbox/%s", filename) 70 | 71 | con <- rawConnection(raw(), "w") 72 | on.exit(close(con)) 73 | if(length(list)) 74 | save(list = list, file = con, envir = envir) 75 | else 76 | save(..., file = con, envir = envir) 77 | 78 | z <- rawConnectionValue(con) 79 | input <- RCurl:::uploadFunctionHandler(z, TRUE) 80 | drop_save <- fromJSON(OAuthRequest(cred, url, , "PUT", upload = TRUE, 81 | readfunction = input, infilesize = length(z), verbose = FALSE, 82 | httpheader = c(`Content-Type` = "application/octet-stream"), 83 | curl = curl, .opts = .opts)) 84 | if (verbose && is.list(drop_save)) { 85 | message("File succcessfully drop_saved to", drop_save$path, 86 | "on", drop_save$modified) 87 | } 88 | drop_save 89 | } 90 | # API documentation: GET: 91 | # https://www.dropbox.com/developers/reference/api#files-GET 92 | -------------------------------------------------------------------------------- /R/dropbox_search.r: -------------------------------------------------------------------------------- 1 | #'Search Dropbox files and folders. 2 | #' 3 | #' If you are searching for a file/folder in the root directory, you can ignore the path. If searching for a file/folder in a specific location, then you should provide a full path to the object. 4 | #' @param cred An object of class DropboxCredentials with Dropobox specific credentials. 5 | #' @param query The search string. Must be at least three characters long. 6 | #' @param deleted If this parameter is set to true, then files and folders that have been deleted will also be included in the search. 7 | #' @param file_limit The maximum and default value is 1,000. No more than file_limit search results will be returned. 8 | #' @param is_dir logical, TRUE looks for directories only. 9 | #' @param verbose logical. Default is FALSE. Set to TRUE to get a full file listing. 10 | #' @param curl If using in a loop, call getCurlHandle() first and pass 11 | #' the returned value in here (avoids unnecessary footprint) 12 | #' @param ... optional additional curl options (debugging tools mostly). 13 | #' @return data.frame with results. No results will return empty data.frame 14 | #' @export dropbox_search 15 | #' @examples \dontrun{ 16 | #' results<-dropbox_search(cred,'file or folder name') 17 | #' results<-dropbox_search(cred,'/specific/path/file or folder name') 18 | #' Returns a small data.frame with path and is_dir 19 | #' results<-dropbox_search(cred,'search_term',verbose=T) 20 | #' Verbose results include a data.frame with columns: revision,rev,thumb_exists,bytes,modified,path,is_dir,icon,root,mime_type,size 21 | #'} 22 | dropbox_search <- function(cred, query = NULL, deleted = FALSE, 23 | file_limit = 1000, is_dir = NULL, verbose = FALSE, curl = getCurlHandle(), 24 | ...) { 25 | if (!is(cred, "DropboxCredentials")) { 26 | stop("Invalid or missing Dropbox credentials. ?dropbox_auth for more information.", 27 | call. = FALSE) 28 | } 29 | if (is.null(query)) { 30 | stop("No term to query") 31 | } 32 | # Save the full path if supplied. 33 | full_path <- query 34 | query <- basename(query) 35 | results <- fromJSON(OAuthRequest(cred, "https://api.dropbox.com/1/search/auto/", 36 | list(query = query, include_deleted = deleted), ..., curl = curl)) 37 | search_results <- formatted_results <- ldply(results, data.frame) 38 | # If user wanted to search for a file in a specific 39 | # location. 40 | if (!identical(full_path, query)) { 41 | search_results <- search_results[which(search_results$path == 42 | full_path), ] 43 | } 44 | # Test if someone is checking whether result is a directory 45 | if (dim(search_results)[1] > 0) { 46 | if (!is.null(is_dir)) { 47 | if (is_dir == TRUE) { 48 | search_results <- search_results[search_results$is_dir, 49 | ] 50 | } 51 | if (is_dir == FALSE) { 52 | search_results <- search_results[!search_results$is_dir, 53 | ] 54 | } 55 | } 56 | } 57 | if (dim(search_results)[1] > 0) { 58 | small_results <- data.frame(path = search_results$path, is_dir = search_results$is_dir) 59 | } 60 | if (dim(search_results)[1] == 0) { 61 | return(search_results[0, 0]) 62 | } 63 | if (!verbose & !empty(small_results)) { 64 | return(small_results) 65 | } 66 | if (verbose & !empty(small_results)) { 67 | return(search_results) 68 | } 69 | } 70 | # API documentation: 71 | # https://www.dropbox.com/developers/reference/api#search 72 | -------------------------------------------------------------------------------- /R/dropbox_serialize.r: -------------------------------------------------------------------------------- 1 | #' Function to save an object from R into Dropbox (not working) 2 | #' 3 | #' This function saves an R object to Dropbox. One can then retrieve it and load 4 | #' it back into R. 5 | #' @param cred Specifies an object of class DropboxCredentials with Dropobox specific credentials. 6 | #' @param list List of objects from the current R environment that needs to be saved into dropbox 7 | #' @param file Required filename. No extenstion needs to be supplied. If you provide one, it will be stripped and replace with rda. 8 | #' @param envir optional. Defaults to parent environment. 9 | #' @param precheck internal use. Checks to make sure all objects are in the parent environment. 10 | #' @param curl If using in a loop, call getCurlHandle() first and pass 11 | #' the returned value in here (avoids unnecessary footprint) 12 | #' @param verbose default is FALSE. Set to true to receive full outcome. 13 | #' @param ... optional additional curl options (debugging tools mostly). 14 | #' @param ext file extension. Default is \code{.rda} 15 | #' @export 16 | #' @return JSON object 17 | #' @examples \dontrun{ 18 | #' dropbox_save(cred, robject, file='filename') 19 | #' dropbox_save(cred, file = 'testRData', .objs = list(a = 1:3, b = letters[1:10])) 20 | #' a = dropbox_get(cred, 'testRData.rdata', binary = TRUE) 21 | #' val = unserialize(rawConnection(a)) 22 | #' 23 | #' # specifying our own name without the standard .rdata 24 | #' dropbox_save(cred, list(a = 1:4, b = letters[1:3]), I('duncan.rda'), verbose = TRUE) 25 | #' # or 26 | #' dropbox_save(cred, list(a = 1:4, b = letters[1:3]), 'duncan', verbose = TRUE, ext = '.rda') 27 | #'} 28 | dropbox_serialize <- 29 | function(cred, file, object, 30 | precheck = TRUE, verbose = FALSE, curl = getCurlHandle(), 31 | ext = ".rda", ...) 32 | { 33 | if (!is(cred, "DropboxCredentials")) 34 | stop("Invalid or missing Dropbox credentials. ?dropbox_auth for more information.", 35 | call. = FALSE) 36 | 37 | if (is.character(file) && !nzchar(file)) 38 | stop("'file' must be non-empty string") 39 | 40 | if(is.character(file)) 41 | file = paste(file, collapse = "/") 42 | 43 | # Allow the caller to force a particular name. 44 | filename <- if(!is(file, "AsIs") && !grepl(sprintf("%s$", ext), file)) 45 | paste(str_trim(str_extract(file, "[^.]*")), ext, sep = "") 46 | else 47 | file 48 | url <- sprintf("https://api-content.dropbox.com/1/files_put/dropbox/%s", 49 | filename) 50 | 51 | z = serialize(object, NULL) 52 | input <- RCurl:::uploadFunctionHandler(z, TRUE) 53 | drop_save <- fromJSON(OAuthRequest(cred, url, , "PUT", upload = TRUE, 54 | readfunction = input, infilesize = length(z), verbose = FALSE, 55 | httpheader = c(`Content-Type` = "application/octet-stream"), 56 | ..., curl = curl)) 57 | if (verbose && is.list(drop_save)) { 58 | message("File succcessfully drop_saved to", drop_save$path, 59 | "on", drop_save$modified) 60 | } 61 | drop_save 62 | } 63 | # API documentation: GET: 64 | # https://www.dropbox.com/developers/reference/api#files-GET 65 | -------------------------------------------------------------------------------- /R/dropbox_share.r: -------------------------------------------------------------------------------- 1 | #' Creates and returns a shareable link to files or folders. 2 | #' 3 | #' Returns a list containing the URL to a zipped copy of a folder or a direct link in 4 | #' case input is a file. Also returns a date when link will expire. 5 | #' @param cred An object of class DropboxCredentials with Dropobox specific credentials. 6 | #' @param file Path to the file or folder you want a shareable link to. 7 | #' @param curl If using in a loop, call getCurlHandle() first and pass 8 | #' the returned value in here (avoids unnecessary footprint) 9 | #' @param ... optional additional curl options (debugging tools mostly). 10 | #' @keywords sharing share_url 11 | #' @seealso \code{\link{dropbox_media}} 12 | #' @export 13 | #' @return list with url to file or zipped folder and expiry date. 14 | #' @examples \dontrun{ 15 | #' dropbox_share(cred, 'test_folder') 16 | #' > dropbox_share(db_cred, 'test_works/test.csv') 17 | #' $url 18 | #' [1] 'http://db.tt/vlwCtRxr' 19 | #' $expires 20 | #' [1] 'Sat, 28 Apr 2012 20:55:42 +0000' 21 | #'} 22 | dropbox_share <- function(cred, file = NULL, curl = getCurlHandle(), 23 | ..., .checkIfExists = TRUE) { 24 | if (!is(cred, "DropboxCredentials")) 25 | stop("Invalid or missing Dropbox credentials. ?dropbox_auth for more information.") 26 | if (is.null(file)) 27 | stop("No file of folder to share", call. = FALSE) 28 | if (.checkIfExists && !(exists.in.dropbox(cred, file, ..., curl = getCurlHandle()))) 29 | stop("Folder doesn't exist", call. = FALSE) 30 | if (grepl("^/", file)) 31 | file <- str_sub(file, 2) 32 | 33 | path_to_share <- sprintf("https://api.dropbox.com/1/shares/dropbox/%s", 34 | file, sep = "") 35 | result <- fromJSON(OAuthRequest(cred, path_to_share, , ..., curl = curl)) 36 | res <- list() 37 | res$url <- result[[1]] 38 | res$expires <- result[[2]] 39 | return(res) 40 | } 41 | # API documentation: 42 | # https://www.dropbox.com/developers/reference/api#shares 43 | -------------------------------------------------------------------------------- /R/dropbox_unserialize.r: -------------------------------------------------------------------------------- 1 | #' @param cred Specifies an object of class DropboxCredentials with Dropobox specific credentials. 2 | #' @param file_to_get Specifies the path to the file you want to retrieve. Path must be relative to \code{Dropbox root}. 3 | #' @param ... additional parameters passed to \code{\link{dropbox_get}}. 4 | #' @param curl If using in a loop, call getCurlHandle() first and pass 5 | #' the returned value in here (avoids unnecessary footprint). 6 | #' @export dropbox_unserialize 7 | #' @return the deserialized R object 8 | #' @examples 9 | #' \dontrun{ 10 | #' dropbox_serialize(drop, "x", 1:10) 11 | #' dropbox_unserialize(drop, "x") 12 | #' 13 | #' dropbox_unserialize(drop, I("x.rda")) 14 | #' } 15 | #' 16 | dropbox_unserialize <- 17 | function(cred, file, precheck = TRUE, verbose = FALSE, curl = getCurlHandle(), 18 | ext = ".rda", ..., .checkIfExists = TRUE) 19 | { 20 | if (!is(cred, "DropboxCredentials")) 21 | stop("Invalid or missing Dropbox credentials. ?dropbox_auth for more information.", 22 | call. = FALSE) 23 | 24 | file <- if(!is(file, "AsIs") && !grepl(sprintf("%s$", ext), file)) 25 | paste(str_trim(str_extract(file, "[^.]*")), ext, sep = "") 26 | else 27 | file 28 | 29 | data = dropbox_get(cred, file, ..., curl = curl, binary = TRUE, .checkIfExists = .checkIfExists) 30 | unserialize(data) 31 | } 32 | 33 | -------------------------------------------------------------------------------- /R/errors.R: -------------------------------------------------------------------------------- 1 | 2 | missingCredentialsError <- 3 | function() 4 | { 5 | raiseError("Invalid or missing Dropbox credentials. ?dropbox_auth for more information.", c("MissingDropboxCredentials", "MissingOAuthCredentials")) 6 | } 7 | 8 | raiseError <- 9 | function(msg, class, ...) 10 | { 11 | e <- structure(list(message = msg, ...), 12 | class = c(class, "rDropError", "simpleError", "error", "condition")) 13 | 14 | stop(e, call = NULL) # , call.= FALSE) 15 | } 16 | 17 | 18 | interruptedUpload <- 19 | function(upload_id, offset) 20 | { 21 | raiseError("", "UploadInterrupted", upload_id = upload_id, offset = offset) 22 | } 23 | -------------------------------------------------------------------------------- /R/startup.r: -------------------------------------------------------------------------------- 1 | .onAttach <- function(...) { 2 | packageStartupMessage("\n\n New to rDrop? Look up ?dropbox_auth() for setting up an app. Use suppressPackageStartupMessages() to suppress this message in future\n") 3 | } 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Do not use this package. I have deprecated this version and replaced it with rDrop2. https://github.com/karthik/rdrop2 2 | 3 | # rDrop: Dropbox interface via R 4 | 5 | This package provides a programmatic interface to [Dropbox](https://www2.dropbox.com/home) from the [R environment](http://www.r-project.org/). The package is complete and fully working but waiting on a dependency to be updated on CRAN before it can be submitted. 6 | 7 | > **Disclaimer: This package is fairly new and likely to contain bugs so please use discretion and report any issues here on github** 8 | 9 | **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: 10 | 11 | ```r 12 | library(devtools) 13 | install_github("duncantl/ROAuth") 14 | ``` 15 | **Without the newest `ROAuth` `rDrop` WILL NOT WORK!** 16 | 17 | # Installing 18 | ```r 19 | library(devtools) 20 | install_github("karthik/rDrop") 21 | ``` 22 | 23 | # Initial setup 24 | * To begin, create an `App` on Dropbox from the [Dropbox developer site](https://www2.dropbox.com/developers/apps). You will need to log in with your Dropbox username and password.Then, click **Create An App**. 25 | 26 | ![Create an app for your personal use on Dropbox](https://github.com/karthikram/rDrop/blob/master/screenshots/create_app.png?raw=true 27 | ) 28 | 29 | * Next, provide a unique (in the universe of Dropbox apps) name to your personal app. Dropbox [branding guidelines](https://www2.dropbox.com/developers/reference/branding) prohibit the use of the word **"Dropbox"** or names that begin with "**Drop**". We recommend that you name the app "**Your_first_name_last_name_rDrop**" to avoid naming conflicts but feel free to call it whatever you like. You won't have to deal with the app name after this step. 30 | 31 | 32 | ![Alt text](https://github.com/karthikram/rDrop/blob/master/screenshots/name_your_app.png?raw=true) 33 | 34 | * Once you click create, be sure to **copy your App key and App secret** and store it somewhere safe. If you forget it, you can always find it [here](https://www.dropbox.com/developers/apps) (Just click on options next to your App name). If you use your `.rprofile` and no one else uses your computer, then we recommend you save your keys there by adding the following lines:

35 | 36 | ```r 37 | options(DropboxKey = "Your_App_key") 38 | options(DropboxSecret = "Your_App_Secret") 39 | ``` 40 | 41 | 42 | 43 | 44 | ![Alt text](https://github.com/karthikram/rDrop/blob/master/screenshots/keys.png?raw=true) 45 | 46 | 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.](https://www2.dropbox.com/account#applications) 47 | 48 | ### Authorizing your app 49 | ```R 50 | library(rDrop) 51 | # If you have Dropbox keys in your .rprofile, simply run: 52 | dropbox_credentials <- dropbox_auth() 53 | # Otherwise: 54 | dropbox_credentials <- dropbox_auth("Your_consumer_key", "Your_consumer_secret") 55 | ``` 56 | 57 | 58 | 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: 59 | 60 | ```R 61 | save(dropbox_credentials, file="/path/to/my_dropbox_credentials.rdata") 62 | ``` 63 | 64 | Credentials will remain valid until you revoke them from your [Dropbox Apps page](https://www2.dropbox.com/developers/apps) by clicking the x next to your App's name. 65 | 66 | # Quick User Guide 67 | This package essentially provides standard Dropbox file operation functions (create/copy/move/restore/share) from within `R`. 68 | 69 | To load a previously validated Dropbox credential file: 70 | 71 | ```R 72 | load('/path/to/my_dropbox_credentials.rdata') 73 | # or once again run, 74 | dropbox_credentials <- dropbox_auth('Your_consumer_key', 'Your_consumer_secret') 75 | ``` 76 | 77 | ### Summary of your Dropbox Account 78 | ```R 79 | dropbox_acc_info(dropbox_credentials) 80 | # will return a list with your display name, email, quota, referral URL, and country. 81 | ``` 82 | 83 | ### Directory listing 84 | ```R 85 | dropbox_dir(dropbox_credentials) 86 | # To list files and folders in your Dropbox root. 87 | dropbox_dir(dropbox_credentials, pattern=".rdata") 88 | # To list files and folders matching a pattern. Any regex should work. 89 | dropbox_dir(dropbox_credentials, verbose = TRUE) 90 | # for a complete listing (filename, revision, thumb, bytes, modified, path, and is_dir) with detailed information. 91 | dropbox_dir(dropbox_credentials, path = 'folder_name') 92 | # To see contents of a specified path. 93 | dropbox_dir(dropbox_credentials, path = 'folder_name', verbose = TRUE) 94 | # For verbose content listing for a specified path (relative to Dropbox root). 95 | ``` 96 | 97 | 98 | ### Download files from your Dropbox account to R 99 | ```R 100 | # Reading text files 101 | file <- dropbox_get(dropbox_credentials, 'my_data.csv') 102 | data <- read.csv(textConnection(file)) 103 | 104 | # Reading CSV files (a wrapper around dropbox_get specific to csv files) 105 | my_data <- db.read.csv(dropbox_credentials, 'my_data.csv', header = TRUE) 106 | 107 | 108 | 109 | # Reading .rdata files 110 | df <- data.frame(x=1:10, y=rnorm(10)) 111 | dropbox_save(dropbox_credentials, df, file="df.rdata") 112 | # Now let's download this file back into R 113 | rm(df) 114 | downloaded_df <- unserialize(dropbox_get(dropbox_credentials, "df.rdata")) 115 | # Another quick/dirty way to read private content from your Dropbox into R is using the dropbox_media() function. 116 | # Example: 117 | source <- dropbox_media(cred, 'test_works/move.txt') 118 | read.csv(source$url) 119 | ``` 120 | 121 | ### Upload R objects to your Dropbox 122 | ```R 123 | # ext default is .rda. 124 | a = 1:4 125 | b = letters[1:3] 126 | dropbox_save(dropbox_credentials, list(a,b), "duncan", verbose = TRUE, ext = ".rda") 127 | ``` 128 | 129 | ### Moving files within Dropobx 130 | ```R 131 | # Note that all paths are relative to your dropbox root. Leave blank or use / for root. 132 | dropbox_move(dropbox_credentials, from_path, to_path) 133 | # from_path can be a folder or file. to_path has to be a folder. 134 | ``` 135 | 136 | ### Copying files within Dropbox 137 | ```r 138 | # Note that all paths are relative to your dropbox root. Leave blank or use / for root. 139 | dropbox_copy(dropbox_credentials, from_path, to_path) 140 | # To overwrite existing file/folder in destination, add overwrite = TRUE. 141 | ``` 142 | 143 | ### Creating a public share for any Dropbox file or folder 144 | ```r 145 | share <- dropbox_share(dropbox_credentials, file) 146 | # returns a list of two elements (url and expires) 147 | share$url # returns a URL to the share 148 | share$expires # shows when the link will expire 149 | # File/folder to share. Returns share URL with expiration information. 150 | # Link goes directly to files. Folder are automatically zipped up. 151 | ``` 152 | 153 | **Reference:** 154 | [Complete Dropbox API Reference.](https://www2.dropbox.com/developers/reference/api) 155 | 156 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | * [Done] Constructor for DropboxCredentials object, separate from dropbox_oauth 2 | Document this. 3 | 4 | * Documentation for classes, etc. 5 | 6 | * GNUmakefile entry for generating documentation, etc. 7 | 8 | * Handle case for dropbox_copy when a DropboxFolder is used for the cred and get the relative paths correct 9 | Somewhat ambigiuous whether both of the from and to paths should be 10 | relative to the dropbox folder. Allow for a absolute path name, 11 | e.g. dropbox_copy(folder, "/a/b/c", "localNameInFolder") 12 | Also allow to name to be omitted when folder implies the same name. 13 | 14 | * [Finish] Class for a path/folder that extends DropboxCredentials and then 15 | uses this to fill the path in requests 16 | Use getPath() to compute the actual path for the requests. 17 | [Done] sanitize_path() 18 | Implement/Check all functions that need to use this. 19 | 20 | [Done] up to dropbox_create_folder 21 | 22 | * [Done] Switched to dir() function and generic 23 | Fix default method for ls() to get correct environment 24 | e.g. ls(2) getting the wrong environment when called from within a function. 25 | 26 | * Fill in getPath() for corner cases (leading /, empty paths) 27 | Fix // cases but not in URL's http://.... 28 | 29 | * [Check] Large files not uploading correctly 30 | Use chunked upload 31 | See dropbox_chunked.r. [Fixed] Problem with signature. Typo! 32 | 33 | If get an error, raise an exception with the upload_id and current 34 | offset. See errors.R but need to connect the code to the error. 35 | 36 | * Make dropbox_save and _put use _chunked if the content is too large. 37 | 38 | * Optionally avoid check.if.exists 39 | Add .checkIfExists = TRUE to functions. 40 | Perhaps use a getOption() for the default value. 41 | 42 | * [low] Allow caching of the folder 43 | Sync API to be informed of update. 44 | use the hash from the /metdata request header. 45 | 46 | * [Started] Conditions and classes for errors. 47 | see raiseError() in errors.R 48 | Used in some functions - grep for stop() 49 | 50 | * Suppress warning message about "No inputs passed to form" from dropbox_acc_info 51 | In ROAuth. 52 | 53 | * Option for list = true for the dropbox_dir() function 54 | 55 | * Why not have dropbox_get and _put use the same parameter name for the file. 56 | _put has what and filename. _get has file_to_get. 57 | Probably use filename for both. 58 | 59 | * get content type correct for dropbox_save 60 | 61 | * have dropbox_save handle ... as named objects 62 | and make it behave better than save which looks for global variables. 63 | Allow both. 64 | 65 | [Done] Ensure dropbox_get obeys the binary 66 | o = dropbox_get(drop, "x.rda", binary = TRUE) 67 | 68 | * Have dropbox_get detect binary. 69 | -------------------------------------------------------------------------------- /inst/doc/ArticlePoints: -------------------------------------------------------------------------------- 1 | 2 | Basics of dropbox 3 | 4 | Why not use a loca folder that automatically updates? 5 | 6 | Can do this with calls to system commands. Not very portable 7 | and unnecessary reading and writing to disk. Also lose 8 | control over the communication (persistent connections), 9 | not as secure (secrets as command line arguments) 10 | Better to do it directly in R. 11 | 12 | Dropbox API is REST and JSON based. 13 | Uses OAuth 1.0 to 14 | 15 | The basic operations are 16 | get and put a document 17 | search for text 18 | information about a document 19 | information about the account and user 20 | 21 | share a document 22 | 23 | list directory 24 | create directory 25 | copy, move/rename, delete 26 | 27 | revisions 28 | restore 29 | 30 | chunked upload 31 | 32 | Add save and load for R objects 33 | 34 | We can use a DropboxCredentials object to invoke methods with 35 | drop$get("filename") 36 | drop$delete("filename") 37 | drop[["filename"]] 38 | 39 | The top-level/root dropbox versus other. 40 | 41 | Give an example/case study of how we would use this and for what purpose. 42 | e.g. provenance? 43 | working on multiple machines, e.g. timings on different machines 44 | write back to a folder for that project with a file for each 45 | then collect in a dynamic document to put on same plot. 46 | 47 | Similar to Amazon S3 - see RAmazonS3, Google Drive. 48 | Would like a common interface and intersection of facilities. 49 | 50 | 51 | Sync API ? -------------------------------------------------------------------------------- /man/DropboxCredentials-class.Rd: -------------------------------------------------------------------------------- 1 | \name{DropboxCredentials-class} 2 | \alias{DropboxCredentials-class} 3 | \title{An S4 class that stores Dropbox credentials} 4 | \description{ 5 | An S4 class that stores Dropbox credentials 6 | } 7 | 8 | -------------------------------------------------------------------------------- /man/db.read.csv.Rd: -------------------------------------------------------------------------------- 1 | \name{db.read.csv} 2 | \alias{db.read.csv} 3 | \title{Read CSV files stored in Dropbox} 4 | \usage{ 5 | db.read.csv(dropbox_credentials, file_to_get) 6 | } 7 | \arguments{ 8 | \item{dropbox_credentials}{Specifies an object of class 9 | DropboxCredentials with Dropobox specific credentials.} 10 | 11 | \item{file_to_get}{Specifies the path to the file you 12 | want to retrieve. Path must be relative to \code{Dropbox 13 | root}.} 14 | } 15 | \value{ 16 | data.frame 17 | } 18 | \description{ 19 | This function is a simple wrapper around 20 | \code{\link{dropbox_get}} for csv files. 21 | } 22 | \examples{ 23 | \dontrun{ 24 | my_data <- db.read.csv(db_cred, 'data.csv', header = TRUE) 25 | } 26 | } 27 | \seealso{ 28 | dropbox_get 29 | } 30 | 31 | -------------------------------------------------------------------------------- /man/dropbox.file.info.Rd: -------------------------------------------------------------------------------- 1 | \name{dropbox.file.info} 2 | \alias{dropbox.file.info} 3 | \title{Return file attributes for a specified file supplied in the path argument.} 4 | \usage{ 5 | dropbox.file.info(cred, path_to_file) 6 | } 7 | \arguments{ 8 | \item{cred}{An object of class DropboxCredentials with 9 | Dropobox specific credentials.} 10 | 11 | \item{path_to_file}{Path to file relative to Dropbox 12 | root.} 13 | } 14 | \value{ 15 | list 16 | } 17 | \description{ 18 | Return file attributes for a specified file supplied in 19 | the path argument. 20 | } 21 | \examples{ 22 | \dontrun{ 23 | dropbox.file.inco(cred, '/folder/file.txt') 24 | } 25 | } 26 | \seealso{ 27 | \code{link{is.dropbox.file}} 28 | } 29 | 30 | -------------------------------------------------------------------------------- /man/dropbox_acc_info.Rd: -------------------------------------------------------------------------------- 1 | \name{dropbox_acc_info} 2 | \alias{dropbox_acc_info} 3 | \title{Retrieve Dropbox account summary} 4 | \usage{ 5 | dropbox_acc_info(cred, curl = getCurlHandle(), ...) 6 | } 7 | \arguments{ 8 | \item{cred}{An object of class DropboxCredentials with 9 | Dropobox specific credentials.} 10 | 11 | \item{curl}{If using in a loop, call getCurlHandle() 12 | first and pass the returned value in here (avoids 13 | unnecessary footprint)} 14 | 15 | \item{...}{optional additional curl options (debugging 16 | tools mostly).} 17 | } 18 | \value{ 19 | list containing \item{referral link}{Dropbox referral 20 | link.} \item{display_name}{Dropbox display name} 21 | \item{uid}{Dropbox user id} \item{country}{Dropbox 22 | country} \item{quota_info}{Information on shared, quota, 23 | and normal.} \item{email}{Dropbox user email} 24 | } 25 | \description{ 26 | Retrieve Dropbox account summary 27 | } 28 | \examples{ 29 | \dontrun{ 30 | dropbox_acc_info(db_cred) 31 | } 32 | } 33 | \seealso{ 34 | related: \code{\link{dropbox_auth}} 35 | } 36 | \keyword{OAuth} 37 | \keyword{authentication} 38 | 39 | -------------------------------------------------------------------------------- /man/dropbox_auth.Rd: -------------------------------------------------------------------------------- 1 | \name{dropbox_auth} 2 | \alias{dropbox_auth} 3 | \alias{rDrop} 4 | \title{rDrop: programmatic access to Dropbox from R.} 5 | \usage{ 6 | dropbox_auth(cKey = getOption("DropboxKey", stop("Missing Dropbox consumer key")), 7 | cSecret = getOption("DropboxSecret", stop("Missing Dropbox app secret")), 8 | curl = getCurlHandle(...), ..., .opts = list(...)) 9 | } 10 | \arguments{ 11 | \item{cKey}{A valid Dropbox application key} 12 | 13 | \item{cSecret}{A valid Dropbox application secret} 14 | 15 | \item{curl}{If using in a loop, call getCurlHandle() 16 | first and pass the returned value in here (avoids 17 | unnecessary footprint)} 18 | 19 | \item{...}{optional additional curl options (debugging 20 | tools mostly).} 21 | } 22 | \value{ 23 | Message with success or error. 24 | 25 | Oauth object of class \code{DropboxCredentials} 26 | } 27 | \description{ 28 | Before using any of rDrop's functions, you must first 29 | create an application on the Dropobox developer site 30 | (\url{https://www2.dropbox.com/developers/apps}). This 31 | application is specific to you. Follow through with the 32 | steps to create your application and copy the generated 33 | consumer key/secret combo. Ideally you should save those 34 | keys (on separate lines) in your options as: 35 | \code{options(DropboxKey = 'Your_App_key')} 36 | \code{options(DropboxSecret = 'Your_App_secret')} If you 37 | are unable to do so (example: Using \code{rDrop} from a 38 | public machine), then you can just specifiy both keys 39 | inline. Once you have authenticated, there is no reason 40 | to repeat this step for subsequent sessions. Simply save 41 | the OAuth object to disk and load it in a script as 42 | necessary. Future versions of ROAuth will make it easier 43 | for you to just update the token (if necessary) without 44 | having to reauthoize via the web. \emph{Do not store 45 | these keys in your .rprofile if you are on a public 46 | machine}. Anyone with access to this ROAuth object will 47 | have full control of your Dropbox account. 48 | } 49 | \details{ 50 | Once you have created an app, retrieve your access keys 51 | using \code{dropbox_auth()} 52 | } 53 | \examples{ 54 | \dontrun{ 55 | dropbox_auth() # if you have keys in .rprofile stored as 56 | # options(DropboxKey='YOUR_APP_KEY') 57 | # options(DropboxSecret='YOUR_SECRET_KEY') 58 | # else use: 59 | dropbox_auth('YOUR_APP_KEY', 'YOUR_APP_SECRET') 60 | dropbox_tokens <- dropbox_auth() 61 | dropbox_token <- dropbox_auth('consumey_key', 'consumer_secret') 62 | save(dropbox_token, file = 'dropbox_auth.rdata') 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /man/dropbox_copy.Rd: -------------------------------------------------------------------------------- 1 | \name{dropbox_copy} 2 | \alias{dropbox_copy} 3 | \alias{dropbox_cp} 4 | \title{Function to copy files or folder within Dropbox.} 5 | \usage{ 6 | dropbox_copy(cred, from_path = NULL, to_path = NULL, 7 | curl = getCurlHandle(), ...) 8 | } 9 | \arguments{ 10 | \item{cred}{An object of class DropboxCredentials with 11 | Dropobox specific credentials.} 12 | 13 | \item{from_path}{Path to file or folder to be copied, 14 | relative to dropbox root.} 15 | 16 | \item{to_path}{Path to destination, including the new 17 | name for the file or folder, relative to dropbox root.} 18 | 19 | \item{curl}{If using in a loop, call getCurlHandle() 20 | first and pass the returned value in here (avoids 21 | unnecessary footprint)} 22 | 23 | \item{...}{optional additional curl options (debugging 24 | tools mostly)..} 25 | } 26 | \value{ 27 | Message with success or error. 28 | } 29 | \description{ 30 | Use this function to copy files or folders within your 31 | Dropbox. Destination must be a folder otherwise the 32 | function will return an error. 33 | } 34 | \examples{ 35 | \dontrun{ 36 | > dropbox_copy(cred, 'copy.txt', 'Public') 37 | /copy.txt succcessfully copied to /Public/copy.txt on Thu, 29 Mar 2012 20:37:51 +0000 38 | } 39 | } 40 | \seealso{ 41 | dropbox_move dropbox_create_folder 42 | 43 | related: \code{\link{dropbox_move}} 44 | } 45 | \keyword{file_copy} 46 | 47 | -------------------------------------------------------------------------------- /man/dropbox_create_folder.Rd: -------------------------------------------------------------------------------- 1 | \name{dropbox_create_folder} 2 | \alias{dropbox_create_folder} 3 | \title{Function to create new folders in Dropbox.} 4 | \usage{ 5 | dropbox_create_folder(cred, folder_name = NULL, 6 | curl = getCurlHandle(), ...) 7 | } 8 | \arguments{ 9 | \item{cred}{An object of class DropboxCredentials with 10 | Dropobox specific credentials.} 11 | 12 | \item{folder_name}{Specifies the path to the new folder 13 | to create relative to root.} 14 | 15 | \item{curl}{If using in a loop, call getCurlHandle() 16 | first and pass the returned value in here (avoids 17 | unnecessary footprint)} 18 | 19 | \item{...}{optional additional curl options (debugging 20 | tools mostly).} 21 | } 22 | \value{ 23 | message with success or failure 24 | } 25 | \description{ 26 | Function to create new folders in Dropbox. 27 | } 28 | \examples{ 29 | \dontrun{ 30 | > dropbox_create_folder(db_cred, 'new_folder') 31 | Folder successfully created at dropbox/new_folder on Thu, 29 Mar 2012 20:51:16 +0000 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /man/dropbox_delete.Rd: -------------------------------------------------------------------------------- 1 | \name{dropbox_delete} 2 | \alias{dropbox_delete} 3 | \title{Function to delete a file or folder from Dropbox} 4 | \usage{ 5 | dropbox_delete(cred, file_to_delete = NULL, 6 | ask = interactive(), curl = getCurlHandle(), ...) 7 | } 8 | \arguments{ 9 | \item{cred}{An object of class DropboxCredentials with 10 | Dropobox specific credentials.} 11 | 12 | \item{file_to_delete}{Specifies the path to the file or 13 | folder to be deleted.} 14 | 15 | \item{curl}{If using in a loop, call getCurlHandle() 16 | first and pass the returned value in here (avoids 17 | unnecessary footprint)} 18 | 19 | \item{...}{optional additional curl options (debugging 20 | tools mostly).} 21 | 22 | \item{ask}{logical set to TRUE. If set to false, function 23 | will not confirm delete operation} 24 | } 25 | \value{ 26 | Nothing. A message upon successful deletion. 27 | } 28 | \description{ 29 | Function will delete specified object in Dropbox 30 | (assuming it exists). To skip deletion conformation, set 31 | ask = FALSE in function call. Accidentally deleted 32 | objects may be recovered using Dropbox's restore feature. 33 | } 34 | \examples{ 35 | \dontrun{ 36 | dropbox_delete(dropbox_credential, 'path/to/file') 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /man/dropbox_dir.Rd: -------------------------------------------------------------------------------- 1 | \name{dropbox_dir} 2 | \alias{dropbox_dir} 3 | \title{Function to list contents of a Dropbox folder.} 4 | \usage{ 5 | dropbox_dir(cred, path = NULL, verbose = FALSE, 6 | deleted = FALSE, pattern = NULL, 7 | curl = getCurlHandle(), ...) 8 | } 9 | \arguments{ 10 | \item{cred}{An object of class DropboxCredentials with 11 | Dropobox specific credentials.} 12 | 13 | \item{path}{The directory to list. Not yet implemented} 14 | 15 | \item{verbose}{logical. FALSE returns a list with file 16 | names in root folder. TRUE returns a \code{data.frame} 17 | with the following fields: id, revision, rev, 18 | thumb_exists, bytes, path, modified, and is_dir} 19 | 20 | \item{deleted}{logical. Default is FALSE. Set to TRUE to 21 | also list deleted files.} 22 | 23 | \item{pattern}{an optional regular expression. Only file 24 | names which match the regular expression will be 25 | returned.} 26 | 27 | \item{curl}{If using in a loop, call getCurlHandle() 28 | first and pass the returned value in here (avoids 29 | unnecessary footprint)} 30 | 31 | \item{...}{optional additional curl options (debugging 32 | tools mostly).} 33 | } 34 | \value{ 35 | directory listing with file or folder names unless 36 | \code{verbose = TRUE} in which case a data.frame is 37 | returned. 38 | } 39 | \description{ 40 | If no folder is specifies, it will only list contents of 41 | the root folder. 42 | } 43 | \examples{ 44 | \dontrun{ 45 | dropbox_dir(db_cred) 46 | dropbox_dir(db_cred, path='/specific_folder') 47 | dropbox_dir(db_cred,path='/specific_folder', verbose = TRUE) 48 | dropbox_dir(db_cred,path='/specific_folder', pattern='file', verbose = TRUE) 49 | returns a dataframe with fields .id, revision, rev, thumb_exists, bytes, modified path, is_dir, icon, root, size, client_mtime, mimetype. 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /man/dropbox_get.Rd: -------------------------------------------------------------------------------- 1 | \name{dropbox_get} 2 | \alias{dropbox_get} 3 | \title{Downloads a file from your Dropbox} 4 | \usage{ 5 | dropbox_get(cred, file_to_get, curl = getCurlHandle(), 6 | ..., binary = NA) 7 | } 8 | \arguments{ 9 | \item{cred}{Specifies an object of class 10 | DropboxCredentials with Dropobox specific credentials.} 11 | 12 | \item{file_to_get}{Specifies the path to the file you 13 | want to retrieve. Path must be relative to \code{Dropbox 14 | root}.} 15 | 16 | \item{curl}{If using in a loop, call getCurlHandle() 17 | first and pass the returned value in here (avoids 18 | unnecessary footprint).} 19 | 20 | \item{binary}{set if the object you are retrieving is 21 | binary.} 22 | 23 | \item{...}{optional additional curl options (debugging 24 | tools mostly)..} 25 | } 26 | \value{ 27 | R object 28 | } 29 | \description{ 30 | Currently the function does not provide much support 31 | other than retrieving the contents of whatever Dropbox 32 | file you specify. Use \code{TextConnection} to process 33 | ascii files for the time being. 34 | } 35 | \examples{ 36 | \dontrun{ 37 | x <- dropbox_get(db_cred, '/folder/file.csv') 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /man/dropbox_media.Rd: -------------------------------------------------------------------------------- 1 | \name{dropbox_media} 2 | \alias{dropbox_media} 3 | \title{Stream data from Dropbox} 4 | \usage{ 5 | dropbox_media(cred, path = NULL, curl = getCurlHandle(), 6 | ...) 7 | } 8 | \arguments{ 9 | \item{cred}{Specifies an object of class 10 | DropboxCredentials with Dropobox specific credentials.} 11 | 12 | \item{path}{Path to object on Dropbox.} 13 | 14 | \item{curl}{If using in a loop, call getCurlHandle() 15 | first and pass the returned value in here (avoids 16 | unnecessary footprint)} 17 | 18 | \item{...}{optional additional curl options (debugging 19 | tools mostly).} 20 | } 21 | \value{ 22 | list with URL to R object and expiration date/time. 23 | } 24 | \description{ 25 | This function behaves very similar to 26 | \code{dropbox_share}. The difference is that this 27 | bypasses the Dropbox webserver, used to provide a preview 28 | of the file, so that you can effectively stream the 29 | contents of your media. 30 | } 31 | \examples{ 32 | \dontrun{ 33 | dropbox_media(db_cred, '/data/file.csv') 34 | } 35 | } 36 | \seealso{ 37 | \code{\link{dropbox_share}} 38 | } 39 | 40 | -------------------------------------------------------------------------------- /man/dropbox_move.Rd: -------------------------------------------------------------------------------- 1 | \name{dropbox_move} 2 | \alias{dropbox_move} 3 | \alias{dropbox_mv} 4 | \title{Move files within Dropbox} 5 | \usage{ 6 | dropbox_move(cred, from_path = NULL, to_path = NULL, 7 | verbose = FALSE, curl = getCurlHandle(), ...) 8 | } 9 | \arguments{ 10 | \item{cred}{Specifies an object of class 11 | DropboxCredentials with Dropobox specific credentials.} 12 | 13 | \item{from_path}{Path to file or folder to be copied, 14 | relative to root.} 15 | 16 | \item{to_path}{Path to destination, including the new 17 | name for the file or folder, relative to root.} 18 | 19 | \item{curl}{If using in a loop, call getCurlHandle() 20 | first and pass the returned value in here (avoids 21 | unnecessary footprint)} 22 | 23 | \item{...}{optional additional curl options (debugging 24 | tools mostly).} 25 | 26 | \item{verbose}{default is FALSE. Set to true to receive 27 | full outcome.} 28 | } 29 | \value{ 30 | Message on successful completion or error. 31 | } 32 | \description{ 33 | Allows users to move files or folders inside the dropbox 34 | storage. 35 | } 36 | \examples{ 37 | \dontrun{ 38 | dropbox_move(cred, 'move.txt','test_works') 39 | File succcessfully moved to /test_works/move.txt on Thu, 29 Mar 2012 20:41:45 +0000 40 | } 41 | } 42 | \seealso{ 43 | dropbox_copy dropbox_create_folder 44 | 45 | related: \code{\link{dropbox_copy}} 46 | } 47 | 48 | -------------------------------------------------------------------------------- /man/dropbox_put.Rd: -------------------------------------------------------------------------------- 1 | \name{dropbox_put} 2 | \alias{dropbox_put} 3 | \title{Function to upload content (in-memory or a file) to Dropbox.} 4 | \usage{ 5 | dropbox_put(cred, what, filename = what, 6 | curl = getCurlHandle(), ..., verbose = FALSE) 7 | } 8 | \arguments{ 9 | \item{cred}{Specifies an object of class 10 | DropboxCredentials with Dropobox specific credentials.} 11 | 12 | \item{what}{the content to upload, which is either the 13 | name of a file, in-memory text or a raw vector.} 14 | 15 | \item{filename}{the name of the file to create in the 16 | Dropbox folder.} 17 | 18 | \item{curl}{If using in a loop, call getCurlHandle() 19 | first and pass the returned value in here (avoids 20 | unnecessary footprint)} 21 | 22 | \item{...}{optional additional curl options (debugging 23 | tools mostly).} 24 | 25 | \item{verbose}{default is FALSE. Set to true to receive 26 | full outcome.} 27 | } 28 | \value{ 29 | information about the uploaded file on dropbox. 30 | } 31 | \description{ 32 | Function to upload content (in-memory or a file) to 33 | Dropbox. 34 | } 35 | \examples{ 36 | \dontrun{ 37 | dropbox_put(auth, 'DESCRIPTION', 'rDrop_DESCRIPTION') 38 | print(dropbox_get(auth, 'rDrop_DESCRIPTION')) 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /man/dropbox_save.Rd: -------------------------------------------------------------------------------- 1 | \name{dropbox_save} 2 | \alias{dropbox_save} 3 | \title{Function to save an object from R into Dropbox (not working)} 4 | \usage{ 5 | dropbox_save(cred, list = character(), 6 | file = stop("'file' must be specified"), 7 | envir = parent.frame(), precheck = TRUE, 8 | verbose = FALSE, curl = getCurlHandle(), ..., 9 | ext = ".rda") 10 | } 11 | \arguments{ 12 | \item{cred}{Specifies an object of class 13 | DropboxCredentials with Dropobox specific credentials.} 14 | 15 | \item{list}{List of objects from the current R 16 | environment that needs to be saved into dropbox} 17 | 18 | \item{file}{Required filename. No extenstion needs to be 19 | supplied. If you provide one, it will be stripped and 20 | replace with rda.} 21 | 22 | \item{envir}{optional. Defaults to parent environment.} 23 | 24 | \item{precheck}{internal use. Checks to make sure all 25 | objects are in the parent environment.} 26 | 27 | \item{curl}{If using in a loop, call getCurlHandle() 28 | first and pass the returned value in here (avoids 29 | unnecessary footprint)} 30 | 31 | \item{verbose}{default is FALSE. Set to true to receive 32 | full outcome.} 33 | 34 | \item{...}{optional additional curl options (debugging 35 | tools mostly).} 36 | 37 | \item{ext}{file extension. Default is \code{.rda}} 38 | } 39 | \value{ 40 | JSON object 41 | } 42 | \description{ 43 | This function saves an R object to Dropbox. One can then 44 | retrieve it and load it back into R. 45 | } 46 | \examples{ 47 | \dontrun{ 48 | dropbox_save(cred, robject, file='filename') 49 | dropbox_save(cred, file = 'testRData', .objs = list(a = 1:3, b = letters[1:10])) 50 | a = dropbox_get(cred, 'testRData.rdata', binary = TRUE) 51 | val = unserialize(rawConnection(a)) 52 | 53 | # specifying our own name without the standard .rdata 54 | dropbox_save(cred, list(a = 1:4, b = letters[1:3]), I('duncan.rda'), verbose = TRUE) 55 | # or 56 | dropbox_save(cred, list(a = 1:4, b = letters[1:3]), 'duncan', verbose = TRUE, ext = '.rda') 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /man/dropbox_search.Rd: -------------------------------------------------------------------------------- 1 | \name{dropbox_search} 2 | \alias{dropbox_search} 3 | \title{Search Dropbox files and folders.} 4 | \usage{ 5 | dropbox_search(cred, query = NULL, deleted = FALSE, 6 | file_limit = 1000, is_dir = NULL, verbose = FALSE, 7 | curl = getCurlHandle(), ...) 8 | } 9 | \arguments{ 10 | \item{cred}{An object of class DropboxCredentials with 11 | Dropobox specific credentials.} 12 | 13 | \item{query}{The search string. Must be at least three 14 | characters long.} 15 | 16 | \item{deleted}{If this parameter is set to true, then 17 | files and folders that have been deleted will also be 18 | included in the search.} 19 | 20 | \item{file_limit}{The maximum and default value is 1,000. 21 | No more than file_limit search results will be returned.} 22 | 23 | \item{is_dir}{logical, TRUE looks for directories only.} 24 | 25 | \item{verbose}{logical. Default is FALSE. Set to TRUE to 26 | get a full file listing.} 27 | 28 | \item{curl}{If using in a loop, call getCurlHandle() 29 | first and pass the returned value in here (avoids 30 | unnecessary footprint)} 31 | 32 | \item{...}{optional additional curl options (debugging 33 | tools mostly).} 34 | } 35 | \value{ 36 | data.frame with results. No results will return empty 37 | data.frame 38 | } 39 | \description{ 40 | If you are searching for a file/folder in the root 41 | directory, you can ignore the path. If searching for a 42 | file/folder in a specific location, then you should 43 | provide a full path to the object. 44 | } 45 | \examples{ 46 | \dontrun{ 47 | results<-dropbox_search(cred,'file or folder name') 48 | results<-dropbox_search(cred,'/specific/path/file or folder name') 49 | Returns a small data.frame with path and is_dir 50 | results<-dropbox_search(cred,'search_term',verbose=T) 51 | Verbose results include a data.frame with columns: revision,rev,thumb_exists,bytes,modified,path,is_dir,icon,root,mime_type,size 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /man/dropbox_share.Rd: -------------------------------------------------------------------------------- 1 | \name{dropbox_share} 2 | \alias{dropbox_share} 3 | \title{Creates and returns a shareable link to files or folders.} 4 | \usage{ 5 | dropbox_share(cred, file = NULL, curl = getCurlHandle(), 6 | ...) 7 | } 8 | \arguments{ 9 | \item{cred}{An object of class DropboxCredentials with 10 | Dropobox specific credentials.} 11 | 12 | \item{file}{Path to the file or folder you want a 13 | shareable link to.} 14 | 15 | \item{curl}{If using in a loop, call getCurlHandle() 16 | first and pass the returned value in here (avoids 17 | unnecessary footprint)} 18 | 19 | \item{...}{optional additional curl options (debugging 20 | tools mostly).} 21 | } 22 | \value{ 23 | list with url to file or zipped folder and expiry date. 24 | } 25 | \description{ 26 | Returns a list containing the URL to a zipped copy of a 27 | folder or a direct link in case input is a file. Also 28 | returns a date when link will expire. 29 | } 30 | \examples{ 31 | \dontrun{ 32 | dropbox_share(cred, 'test_folder') 33 | > dropbox_share(db_cred, 'test_works/test.csv') 34 | $url 35 | [1] 'http://db.tt/vlwCtRxr' 36 | $expires 37 | [1] 'Sat, 28 Apr 2012 20:55:42 +0000' 38 | } 39 | } 40 | \seealso{ 41 | \code{\link{dropbox_media}} 42 | } 43 | \keyword{share_url} 44 | \keyword{sharing} 45 | 46 | -------------------------------------------------------------------------------- /man/exists.in.dropbox.Rd: -------------------------------------------------------------------------------- 1 | \name{exists.in.dropbox} 2 | \alias{exists.in.dropbox} 3 | \title{Check to see if an object exists in Dropbox} 4 | \usage{ 5 | exists.in.dropbox(cred, path = NULL, is_dir = NULL, ..., 6 | curl = getCurlHandle()) 7 | } 8 | \arguments{ 9 | \item{cred}{An object of class DropboxCredentials with 10 | Dropobox specific credentials.} 11 | 12 | \item{path}{Path to object} 13 | 14 | \item{is_dir}{if set to TRUE, will only look for folders. 15 | Otherwise will return file or folder.} 16 | 17 | \item{curl}{If using in a loop, call getCurlHandle() 18 | first and pass} 19 | 20 | \item{...}{optional additional curl options (debugging 21 | tools mostly).} 22 | } 23 | \value{ 24 | logical. TRUE/FALSE 25 | } 26 | \description{ 27 | This function is meant for internal use especially when 28 | copying or moving files. 29 | } 30 | \examples{ 31 | \dontrun{ 32 | exists.in.dropbox(cred,'test_folder') 33 | exists.in.dropbox(cred,'test_folder',is_dir='dir') 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /man/sanitize_paths.Rd: -------------------------------------------------------------------------------- 1 | \name{sanitize_paths} 2 | \alias{sanitize_paths} 3 | \title{Verify paths for copy and move operations} 4 | \usage{ 5 | sanitize_paths(from_path, to_path = NULL) 6 | } 7 | \arguments{ 8 | \item{from_path}{source path} 9 | 10 | \item{to_path}{destination path. Leave blank for dropbox 11 | root.} 12 | } 13 | \value{ 14 | list with clean paths 15 | } 16 | \description{ 17 | Function is meant for internal use in 18 | \code{\link{dropbox_move}} and \code{\link{dropbox_copy}} 19 | } 20 | \examples{ 21 | \dontrun{ 22 | santize_paths(from_path, to_path) 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /screenshots/create_app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karthik/rDrop/676b2f1bf0309fac4552bdb3a4e08280c1064d5f/screenshots/create_app.png -------------------------------------------------------------------------------- /screenshots/keys.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karthik/rDrop/676b2f1bf0309fac4552bdb3a4e08280c1064d5f/screenshots/keys.png -------------------------------------------------------------------------------- /screenshots/name_your_app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karthik/rDrop/676b2f1bf0309fac4552bdb3a4e08280c1064d5f/screenshots/name_your_app.png -------------------------------------------------------------------------------- /tests/deleteFolder.R: -------------------------------------------------------------------------------- 1 | library(rDrop) 2 | source("getCred.R") 3 | 4 | if(!is.null(drop <- getCred())) { 5 | dummy = DropboxFolder("Dummy", drop) 6 | e = dropbox_create_folder(dummy, "Extra") 7 | e = dropbox_delete(dummy, "Extra") 8 | } 9 | -------------------------------------------------------------------------------- /tests/dropbox_save.R: -------------------------------------------------------------------------------- 1 | library(rDrop) 2 | 3 | source("getCred.R") 4 | 5 | if(!is.null(drop <- getCred())) 6 | { 7 | 8 | a = 1:10 9 | b = pi 10 | c = LETTERS 11 | d = rnorm 12 | 13 | dropbox_save(drop, a, b, c, d, file = "rDropTest") 14 | 15 | rm(a, b, c, d) 16 | dropbox_load(drop, "rDropTest.rda") 17 | } 18 | -------------------------------------------------------------------------------- /tests/folderClass.R: -------------------------------------------------------------------------------- 1 | library(rDrop) 2 | source("getCred.R") 3 | 4 | if(!is.null(drop <- getCred())) 5 | { 6 | dummy = DropboxFolder("Dummy", drop) 7 | objs = ls(dummy) 8 | dummy[[objs[1], .checkIfExists = FALSE]] 9 | } 10 | -------------------------------------------------------------------------------- /tests/folderLS.R: -------------------------------------------------------------------------------- 1 | library(rDrop) 2 | source("getCred.R") 3 | 4 | if(!is.null(drop <- getCred())) 5 | { 6 | dummy = DropboxFolder("Dummy", drop) 7 | dropbox_dir(dummy) 8 | ls(dummy) 9 | } 10 | -------------------------------------------------------------------------------- /tests/getCred.R: -------------------------------------------------------------------------------- 1 | getCred <- 2 | function() 3 | { 4 | ff <- getOption("DROPBOX_OAUTH_RDA", "") 5 | if(ff == "") 6 | ff <- Sys.getenv("DROPBOX_OAUTH_RDA") 7 | 8 | if(ff != "" && file.exists(ff)) { 9 | what = load(ff, globalenv()) 10 | get(what, globalenv()) 11 | } else 12 | stop("cannot find saved dropbox credentials. Set it using the envirornment variable DROPBOX_AUTH_RDA") 13 | } 14 | 15 | -------------------------------------------------------------------------------- /tests/serialize.R: -------------------------------------------------------------------------------- 1 | library(rDrop) 2 | 3 | source("getCred.R") 4 | 5 | if(!is.null(drop <- getCred())) 6 | { 7 | 8 | dropbox_serialize(drop, "x", 1:10) 9 | dropbox_unserialize(drop, "x") 10 | 11 | dropbox_unserialize(drop, I("x.rda")) 12 | } 13 | --------------------------------------------------------------------------------