Skip to content

Commit

Permalink
Merge pull request #40 from florisvdh/humansize
Browse files Browse the repository at this point in the history
Drop assertthat and dplyr dependencies
  • Loading branch information
eblondel committed Sep 2, 2020
2 parents be9443f + 6966972 commit 23eb128
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Authors@R: c(
person("Floris", "Vanderhaeghe", role = c("ctb"), comment = c(ORCID = "0000-0002-6378-6229")))
Maintainer: Emmanuel Blondel <emmanuel.blondel1@gmail.com>
Depends: R (>= 3.3.0), methods
Imports: R6, httr, jsonlite, xml2, keyring, tools, assertthat, dplyr, parallel
Imports: R6, httr, jsonlite, xml2, keyring, tools, parallel
Suggests: testthat
Description: Provides an Interface to 'Zenodo' (<https://zenodo.org>) REST API,
including management of depositions, attribution of DOIs by 'Zenodo' and
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import(keyring)
import(methods)
import(xml2)
importFrom(R6,R6Class)
importFrom(assertthat,assert_that)
importFrom(dplyr,"%>%")
importFrom(parallel,mclapply)
importFrom(tools,file_path_as_absolute)
importFrom(tools,md5sum)
4 changes: 2 additions & 2 deletions R/ZenodoRecord.R
Original file line number Diff line number Diff line change
Expand Up @@ -1158,13 +1158,13 @@ ZenodoRecord <- R6Class("ZenodoRecord",
}else{
files_summary <- sprintf("Will download %s file%s from record '%s' (doi: '%s') - total size: %s",
length(self$files), ifelse(length(self$files)>1,"s",""), self$id, self$doi,
sum(sapply(self$files, function(x){x$filesize})) %>% human_filesize())
human_filesize(sum(sapply(self$files, function(x){x$filesize}))))

#download_file util
download_file <- function(file){
file$filename <- gsub("/", "_", file$filename)
if (!quiet) cat(sprintf("[zen4R][INFO] Downloading file '%s' - size: %s\n",
file$filename, file$filesize %>% human_filesize()))
file$filename, human_filesize(file$filesize)))
target_file <-file.path(path, file$filename)
download.file(url = file$links$download, destfile = target_file,
quiet = quiet, mode = "wb")
Expand Down
2 changes: 0 additions & 2 deletions R/zen4R.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#' @import keyring
#' @importFrom tools file_path_as_absolute
#' @importFrom tools md5sum
#' @importFrom assertthat assert_that
#' @importFrom dplyr %>%
#' @importFrom parallel mclapply
#'
#' @title Interface to 'Zenodo' REST API
Expand Down
9 changes: 2 additions & 7 deletions R/zen4R_downloader.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,7 @@ download_zenodo = function(doi, path = ".", logger = NULL, quiet = FALSE, ...){
#' @keywords internal
#'
human_filesize <- function(x) {
assert_that(is.numeric(x))
assert_that(all(x %% 1 == 0 & x >= 0))
magnitude <-
log(x, base = 1024) %>%
floor %>%
pmin(8)
magnitude <- pmin(floor(log(x, base = 1024)), 8)
unit <- factor(magnitude,
levels = 0:8,
labels = c(
Expand All @@ -82,6 +77,6 @@ human_filesize <- function(x) {
"ZiB",
"YiB")
)
size <- (x / 1024^magnitude) %>% round(1)
size <- round(x / 1024^magnitude, 1)
return(paste(size, unit))
}

0 comments on commit 23eb128

Please sign in to comment.