Skip to content

Passing dots arguments through a target factory #84

Closed Answered by wlandau
petrbouchal asked this question in Help
Discussion options

You must be logged in to vote

rlang has nice functions for this, especially enexprs(). rlang::call2() almost fits, but base::as.call() may be a little better for the situation.

library(targets)

tar_script({
  tar_read_data <- function(name, file, reader, ...) {
    name_read <- deparse(rlang::enexpr(name))
    name_file <- paste0(name_read, "_file")
    sym_file <- rlang::sym(name_file)
    expr_read <- as.call(rlang::enexprs(reader, sym_file, ...))
    list(
      targets::tar_target_raw(name_file, file, format = "file"),
      targets::tar_target_raw(name_read, expr_read)
    )
  }

  tar_read_data(data, "data.csv", read_csv, skip = 5, col_types = cols())
})

tar_manifest(fields = all_of(c("command", "format")))
#>…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@petrbouchal
Comment options

@petrbouchal
Comment options

@wlandau
Comment options

@petrbouchal
Comment options

Answer selected by petrbouchal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants