diff --git a/R/boxr__internal_misc.R b/R/boxr__internal_misc.R index ec23b65..d63d935 100644 --- a/R/boxr__internal_misc.R +++ b/R/boxr__internal_misc.R @@ -25,7 +25,7 @@ as_box_id <- function(x, arg = rlang::caller_arg(x), # a box_id is a string that contains only digits - # do we need this? + # some defaults are NULL; we just pass these through if (is.null(x)) { return(NULL) } diff --git a/R/boxr_misc.R b/R/boxr_misc.R index f8ecf8e..d2779f7 100644 --- a/R/boxr_misc.R +++ b/R/boxr_misc.R @@ -306,6 +306,10 @@ boxDirCreate <- function(dir_name, parent_dir_id = box_getwd()) { #' @export #' box_browse <- function(dir_id = NULL, file_id = NULL) { + + dir_id <- as_box_id(dir_id) + file_id <- as_box_id(file_id) + item <- collab_item_helper(dir_id, file_id) utils::browseURL(glue::glue("https://app.box.com/{item$type}/{item$id}")) } diff --git a/R/boxr_read.R b/R/boxr_read.R index feff538..87a06be 100644 --- a/R/boxr_read.R +++ b/R/boxr_read.R @@ -53,6 +53,7 @@ box_read <- function(file_id, type = NULL, version_id = NULL, version_no = NULL, read_fun = rio::import, ...) { checkAuth() + file_id <- as_box_id(file_id) temp_file <- tempfile() @@ -122,6 +123,7 @@ box_read <- function(file_id, type = NULL, version_id = NULL, #' @rdname box_read #' @export box_read_csv <- function(file_id, ...) { + file_id <- as_box_id(file_id) box_read(file_id, format = "csv", ...) } @@ -129,6 +131,7 @@ box_read_csv <- function(file_id, ...) { #' @rdname box_read #' @export box_read_tsv <- function(file_id, ...) { + file_id <- as_box_id(file_id) box_read(file_id, format = "tsv", ...) } @@ -136,6 +139,7 @@ box_read_tsv <- function(file_id, ...) { #' @rdname box_read #' @export box_read_json <- function(file_id, ...) { + file_id <- as_box_id(file_id) box_read(file_id, read_fun = jsonlite::fromJSON, ...) } @@ -143,12 +147,14 @@ box_read_json <- function(file_id, ...) { #' @rdname box_read #' @export box_read_excel <- function(file_id, ...) { + file_id <- as_box_id(file_id) box_read(file_id, format = "excel", ...) } #' @rdname box_read #' @export box_read_rds <- function(file_id, ...) { + file_id <- as_box_id(file_id) box_read(file_id, read_fun = readRDS, ...) } diff --git a/R/boxr_save_load.R b/R/boxr_save_load.R index 6884f3e..5e024a4 100644 --- a/R/boxr_save_load.R +++ b/R/boxr_save_load.R @@ -50,6 +50,8 @@ box_save <- function(..., dir_id = box_getwd(), file_name = ".RData", box_save_image <- function(dir_id = box_getwd(), file_name = ".RData", description = NULL, filename) { + dir_id <- as_box_id(dir_id) + # TODO: in future version, remove argument if (!missing(filename)) { @@ -75,7 +77,10 @@ box_save_image <- function(dir_id = box_getwd(), file_name = ".RData", #' @rdname box_save #' @export #' -box_load <- function(file_id) { +box_load <- function(file_id) { + + file_id <- as_box_id(file_id) + temp_dir <- tempdir() temp_file <- box_dl(file_id, overwrite = TRUE, local_dir = temp_dir) on.exit(fs::file_delete(temp_file)) diff --git a/R/boxr_write.R b/R/boxr_write.R index 5b6006a..8dfd90d 100644 --- a/R/boxr_write.R +++ b/R/boxr_write.R @@ -43,6 +43,8 @@ box_write <- function(object, file_name, dir_id = box_getwd(), description = NULL, write_fun = rio::export, x, filename, ...) { + dir_id <- as_box_id(dir_id) + # TODO: in future version, remove argument if (!missing(filename)) { @@ -78,6 +80,8 @@ box_write <- function(object, file_name, dir_id = box_getwd(), description = NUL box_save_rds <- function(object, dir_id = box_getwd(), file_name = ".RDS", description = NULL) { + dir_id <- as_box_id(dir_id) + temp_file <- fs::path_temp(file_name) on.exit(fs::file_delete(temp_file))