Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import remake project #6

Open
krlmlr opened this issue Feb 6, 2017 · 4 comments
Open

Import remake project #6

krlmlr opened this issue Feb 6, 2017 · 4 comments

Comments

@krlmlr
Copy link
Collaborator

krlmlr commented Feb 6, 2017

Started a project with remake, now want to try your package. Challenge: Get a working workflow.R from a remake.yml file. The following code worked for me:

library(tibble)
library(dplyr)
library(forcats)
library(tidyr)

is_syntactic <- function(x) {
  ret <- make.names(x) == x
  ret[is.na(x)] <- FALSE
  ret
}

tickit <- function(x) {
  needs_ticks <- !is_syntactic(x)
  x[needs_ticks] <- paste0("`", gsub("`", "\\\\`", x[needs_ticks]), "`")
  x
}

remake <- yaml::yaml.load_file("remake.yml")

library <- "library(remakeGenerator)"

commands <-
  remake$targets %>%
  enframe("target") %>%
  mutate(target = fct_inorder(target)) %>%
  mutate(value = lapply(value, enframe)) %>%
  unnest %>%
  spread(name, value) %>%
  mutate(command = unlist(command)) %>%
  summarize(text = paste0(tickit(as.character(target)), " = ", command, collapse = ",\n  ")) %>%
  { paste0("commands <- commands(\n  ", .$text, ")") }

targets <- "targets <- targets(imported = commands)"

packages <- paste0("packages <- c(", paste0('"', remake$packages, '"', collapse = ", "), ")")

sources <- paste0("sources <- c(", paste0('"', remake$sources, '"', collapse = ", "), ")")

workflow <- "workflow(targets = targets, sources = sources, packages = packages)"

con <- file("workflow.R", "w+")

writeLines(c(
  library, "",
  commands, "",
  targets, "",
  packages, "",
  sources, "",
  workflow), con)

close(con)

Let me know if you'd support something like this in your package.

@wlandau
Copy link
Owner

wlandau commented Feb 6, 2017

Neat idea, @krlmlr! I would absolutely support this. Got a pull request in mind?

@krlmlr
Copy link
Collaborator Author

krlmlr commented Feb 6, 2017

I'll let it simmer a bit. Probably the packages used by this script should be added as "Suggests:"?

@wlandau
Copy link
Owner

wlandau commented Feb 7, 2017

If we plan to subsume this script into remakeGenerator as a function (maybe something like import_remake("remake.yml") or recover_generator("remake.yml")), I'm actually hoping to use "Imports:" and importFrom rather than "Suggests:". Sound okay?

Also, just so I understand: what is the role of backticks in parsing the targets? If you use commands_string() or commands_batch() instead of commands(), will we still need to be as careful as you are about how symbol are handled?

I just tried your script on the remake.yml from example_remakeGenerator("basic"); source("basic/workflow.R"), and I got "Error: wrong result size (25), expected 34 or 1" on mutate(command = unlist(command)). I'm using R 3.3.2 and the latest CRAN releases of tibble, dplyr, forcats, and tidyr.

@wlandau
Copy link
Owner

wlandau commented Feb 7, 2017

Also, no rush on the pull request. Regardless of which one of us gets to this first, let's make sure to add you as a contributor when the functionality is implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants