Skip to content

Commit

Permalink
added smart_download; #22
Browse files Browse the repository at this point in the history
  • Loading branch information
beanumber committed May 26, 2016
1 parent 7462a28 commit 06fadfa
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 29 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: etl
Type: Package
Title: Extract-Transfer-Load Framework for Medium Data
Version: 0.2.2.9011
Version: 0.2.2.9012
Authors@R: as.person(c(
"Ben Baumer <[email protected]> [aut, cre]",
"Carson Sievert <[email protected]> [ctb]"
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export(etl_extract)
export(etl_load)
export(etl_transform)
export(etl_update)
export(files_that_dont_exist)
export(get_schema)
export(is.etl)
export(smart_download)
import(RSQLite)
import(dplyr)
importFrom(DBI,SQL)
Expand Down
15 changes: 9 additions & 6 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,18 @@ get_schema.src_postgres <- function(con, schema_name, pkg, ...) {
NextMethod(ext = "psql")
}

#' Check for files that don't already exist
#' Download only those files that don't already exist
#' @param obj an \code{\link{etl}} object
#' @param src a character vector of paths to filenames that you want to have
#' @param dir a path to a directory where you want the files to be
#' @return a logical vector of the same length as \code{src} indicating which
#' @param ... arguments passed to \code{\link[utils]{download.file}}
#' @details Downloads only those files in \code{src} that are not already present
#' the \code{raw_dir} attribute of \code{obj}
#' files in \code{src} do not already exist in \code{dir}.
#' @export
files_that_dont_exist <- function(src, dir) {
lcl <- paste0(dir, "/", basename(src))
smart_download <- function(obj, src, ...) {
lcl <- paste0(attr(obj, "raw_dir"), "/", basename(src))
missing <- !file.exists(lcl)
return(missing)
mapply(utils::download.file, src[missing], lcl[missing])
}


21 changes: 0 additions & 21 deletions man/files_that_dont_exist.Rd

This file was deleted.

24 changes: 24 additions & 0 deletions man/smart_download.Rd

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

0 comments on commit 06fadfa

Please sign in to comment.