diff --git a/DESCRIPTION b/DESCRIPTION index 418a714..80af105 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 , including support for all standard file operations. Depends: R (>= 3.1.1) @@ -19,7 +24,8 @@ Imports: jsonlite, magrittr, purrr, - readxl + readxl, + openxlsx Suggests: testthat, uuid -RoxygenNote: 7.1.1 +RoxygenNote: 7.1.2 diff --git a/NAMESPACE b/NAMESPACE index 4fcced0..bfa4b9a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/drop_read.R b/R/drop_read.R index a068336..abbdee0 100644 --- a/R/drop_read.R +++ b/R/drop_read.R @@ -1,16 +1,17 @@ #' drop_read #' -#' @description wrapper for importing read.csv, read_excel readRDS and load from dropbox +#' @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{readxl} or \code(readRDS) or \code(load) -#' @importFrom rdrop2 drop_download drop_upload +#' @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") @@ -41,7 +42,7 @@ drop_read <- function (file, dest = tempdir(), - dtoken = rdrop2:::get_dropbox_token(), + dtoken = get_dropbox_token(), ...){ localfile = paste0(dest, "/", basename(file)) drop_download(file, localfile, overwrite = TRUE, dtoken = dtoken) diff --git a/R/drop_save.R b/R/drop_save.R new file mode 100644 index 0000000..a103028 --- /dev/null +++ b/R/drop_save.R @@ -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) + +} diff --git a/man/drop_read.Rd b/man/drop_read.Rd new file mode 100644 index 0000000..0ced951 --- /dev/null +++ b/man/drop_read.Rd @@ -0,0 +1,53 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/drop_read.R +\name{drop_read} +\alias{drop_read} +\title{drop_read} +\usage{ +drop_read(file, dest = tempdir(), dtoken = get_dropbox_token(), ...) +} +\arguments{ +\item{file}{path on dropbox} + +\item{dest}{local path. tempdir for default} + +\item{dtoken}{token} + +\item{...}{other arguments according to file format +into \code{read.csv} or \code{read_excel} or \code{readRDS} or \code{load}} +} +\description{ +wrapper for importing read.csv, +read_excel readRDS and load from dropbox +} +\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") + +} +} +\author{ +Lewis Hounkpevi +} diff --git a/man/drop_save.Rd b/man/drop_save.Rd new file mode 100644 index 0000000..aae85d6 --- /dev/null +++ b/man/drop_save.Rd @@ -0,0 +1,66 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/drop_save.R +\name{drop_save} +\alias{drop_save} +\title{drop_save} +\usage{ +drop_save( + object, + path = NULL, + mode = "overwrite", + autorename = TRUE, + mute = FALSE, + verbose = FALSE, + dtoken = get_dropbox_token(), + ext = c("csv", "xlsx", "rds", "RData"), + ... +) +} +\arguments{ +\item{object}{R object to save} + +\item{path}{The relative path on Dropbox where the file should get uploaded.} + +\item{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 -} + +\item{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`} + +\item{mute}{Set to FALSE to prevent a notification trigger on the desktop and +mobile apps} + +\item{verbose}{By default verbose output is \code{FALSE}. Set to \code{TRUE} +if you need to troubleshoot any output or grab additional parameters.} + +\item{dtoken}{The Dropbox token generated by \code{\link{drop_auth}}. rdrop2 +will try to automatically locate your local credential cache and use them. +However, if the credentials are not found, the function will initiate a new +authentication request. You can override this in \code{\link{drop_auth}} by +pointing to a different location where your credentials are stored.} + +\item{ext}{file extension that will be saved. here we suggest csv, excel, rds, RData} + +\item{...}{other arguments for write.csv, write.xlsx, readRDS, save} +} +\description{ +drop_save +} +\examples{ +\dontrun{ +drop_save(BOD, ext = "rds") +drop_save(BOD, ext = "RData") +drop_save(BOD, ext = "xlsx") +drop_save(BOD, ext = "csv") +} +} +\references{ +\href{https://www.dropbox.com/developers/documentation/http/documentation#files-upload}{API documentation} +} +\author{ +Lewis Hounkpevi +} diff --git a/tests/testthat/test-99-rdrop2.R b/tests/testthat/test-99-rdrop2.R index 304ae7e..65cc3f2 100644 --- a/tests/testthat/test-99-rdrop2.R +++ b/tests/testthat/test-99-rdrop2.R @@ -25,7 +25,7 @@ test_that("drop_share works correctly", { }) -# drop_search +drop_search test_that("drop_search works correctly", { skip_on_cran() @@ -82,27 +82,27 @@ test_that("drop_history works correctly", { }) -# drop_exists -# test_that("drop_exists works correctly", { -# skip_on_cran() -# -# folder_name <- traceless("drop_exists") -# drop_create(folder_name) -# -# expect_true(drop_exists(folder_name)) -# expect_false(drop_exists(traceless("stuffnthings"))) -# -# # Now test files inside subfolders -# write.csv(iris, file = "iris.csv") -# drop_upload("iris.csv", path = folder_name) -# expect_true(drop_exists(paste0(folder_name, "/iris.csv"))) -# -# #cleanup -# drop_delete(folder_name) -# unlink("iris.csv") -# }) -# -# +drop_exists +test_that("drop_exists works correctly", { + skip_on_cran() + + folder_name <- traceless("drop_exists") + drop_create(folder_name) + + expect_true(drop_exists(folder_name)) + expect_false(drop_exists(traceless("stuffnthings"))) + + # Now test files inside subfolders + write.csv(iris, file = "iris.csv") + drop_upload("iris.csv", path = folder_name) + expect_true(drop_exists(paste0(folder_name, "/iris.csv"))) + + #cleanup + drop_delete(folder_name) + unlink("iris.csv") +}) + + # # drop_media # test_that("drop_media works correctly", { # skip_on_cran()