Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ Version: 0.8.2.1
Authors@R: c(person("Karthik", "Ram", email = "karthik.ram@gmail.com", role = c("aut", "cre")),
person("Clayton", "Yochum", role = "aut"),
person("Caleb", "Scheidel", role = "ctb"),
person("Akhil", "Bhel", role = "cph")
person("Akhil", "Bhel", role = "cph"),
person(given = "Lewis",
family = "Hounkpevi",
role = "ctb",
email = "lewis.hounkpevi@gmail.com",
comment = c(ORCID = "0000-0001-5111-8568"))
)
Description: Provides full programmatic access to the 'Dropbox' file hosting platform <https://dropbox.com>, including support for all standard file operations.
Depends: R (>= 3.1.1)
Expand All @@ -18,7 +23,9 @@ Imports:
httr,
jsonlite,
magrittr,
purrr
purrr,
readxl,
openxlsx
Suggests: testthat,
uuid
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ export(drop_history)
export(drop_list_shared_links)
export(drop_media)
export(drop_move)
export(drop_read)
export(drop_read_csv)
export(drop_save)
export(drop_search)
export(drop_share)
export(drop_upload)
import(httr)
importFrom(magrittr,"%>%")
importFrom(openxlsx,write.xlsx)
importFrom(readxl,read_excel)
importFrom(utils,write.csv)
68 changes: 68 additions & 0 deletions R/drop_read.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#' drop_read
#'
#' @description wrapper for importing read.csv,
#' read_excel readRDS and load from dropbox
#'
#' @param file path on dropbox
#' @param dest local path. tempdir for default
#' @param dtoken token
#' @param ... other arguments according to file format
#' into \code{read.csv} or \code{read_excel} or \code{readRDS} or \code{load}
#' @importFrom readxl read_excel
#' @author Lewis Hounkpevi
#' @export
#' @examples \dontrun{
#' save(airquality, file = "airquality.RData")
#' save(attenu, file = "attenu.RData")
#' save(austres, file = "austres.RData")
#' saveRDS(AirPassengers, "AirPassengers.rds")
#' write.csv(mtcars, file = "mtcars.csv")
#' openxlsx::write.xlsx(iris, file = "iris.xlsx")
#' purrr::walk(c("airquality.RData",
#' "attenu.RData",
#' "austres.RData",
#' "AirPassengers.rds",
#' "mtcars.csv",
#' "iris.xlsx"),
#'
#' ~ rdrop2::drop_upload(.x,
#' path = "/", # path in dropbox
#' mode = "overwrite"
#' ))
#' drop_read(file = "AirPassengers.rds")
#' drop_read("iris.xlsx")
#' drop_read("mtcars.csv")
#' drop_read("airquality.RData")
#' drop_read("attenu.RDATA")
#' drop_read("austres.rdata")
#'
#' }



drop_read <- function (file,
dest = tempdir(),
dtoken = get_dropbox_token(),
...){
localfile = paste0(dest, "/", basename(file))
drop_download(file, localfile, overwrite = TRUE, dtoken = dtoken)

ext <- strsplit(basename(file), split = "\\.")[[1]][-1]

if(ext == "csv") {
utils::read.csv(localfile, ...)

}else if (ext == "xlsx" | ext == "xls"){

readxl::read_excel(localfile, ...)

} else if(ext == "rds" ){

readRDS(localfile, ...)

} else if (ext == "RData" | ext == "rdata" | ext == "RDATA" | ext == "rda") {

load(localfile, envir = .GlobalEnv, ...)
}

}
74 changes: 74 additions & 0 deletions R/drop_save.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#' drop_save
#'
#'@param object R object to save
#'@param path The relative path on Dropbox where the file should get uploaded.
#'@param mode - "add" - will not overwrite an existing file in case of a
#' conflict. With this mode, when a a duplicate file.txt is uploaded, it will
#' become file (2).txt. - "overwrite" will always overwrite a file -
#'@param autorename This logical determines what happens when there is a
#' conflict. If true, the file being uploaded will be automatically renamed to
#' avoid the conflict. (For example, test.txt might be automatically renamed to
#' test (1).txt.) The new name can be obtained from the returned metadata. If
#' false, the call will fail with a 409 (Conflict) response code. The default is `TRUE`
#'@param mute Set to FALSE to prevent a notification trigger on the desktop and
#' mobile apps
#'@template verbose
#'@template token
#'@references \href{https://www.dropbox.com/developers/documentation/http/documentation#files-upload}{API documentation}
#'@param ext file extension that will be saved. here we suggest csv, excel, rds, RData
#'@param ... other arguments for write.csv, write.xlsx, readRDS, save
#'@importFrom openxlsx write.xlsx
#'@importFrom utils write.csv
#'@author Lewis Hounkpevi
#'@export
#'
#' @examples \dontrun{
#' drop_save(BOD, ext = "rds")
#' drop_save(BOD, ext = "RData")
#' drop_save(BOD, ext = "xlsx")
#' drop_save(BOD, ext = "csv")
#'}
drop_save <- function (object,
path = NULL,
mode = "overwrite",
autorename = TRUE,
mute = FALSE,
verbose = FALSE,
dtoken = get_dropbox_token(),
ext = c("csv", "xlsx", "rds", "RData"),
...){


localpath <- paste0(tempdir(), "/", deparse(substitute(object)), ".", ext)



if(ext == "csv") {

write.csv(object, file = localpath, ...)

}else if (ext == "xlsx" | ext == "xls"){

openxlsx::write.xlsx(object, file = localpath, ...)

} else if(ext == "rds" ){

saveRDS(object, file = localpath, ...)

} else if (ext == "RData" | ext == "rdata" | ext == "RDATA") {

save(object, file = localpath, ...)
}




drop_upload(file = localpath,
path = path,
mode = mode,
autorename = autorename,
mute = mute,
verbose = verbose,
dtoken = dtoken)

}
53 changes: 53 additions & 0 deletions man/drop_read.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions man/drop_save.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading