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

Commands as language objects by default #708

Merged
merged 53 commits into from
Feb 3, 2019
Merged

Commands as language objects by default #708

merged 53 commits into from
Feb 3, 2019

Conversation

wlandau
Copy link
Collaborator

@wlandau wlandau commented Feb 3, 2019

Summary

Until now, drake has used text to represent commands. It worked, but it was naive.

plan <- drake_plan(
  raw_data = readxl::read_excel(file_in("raw_data.xlsx")),
  data = raw_data %>%
    mutate(Species = forcats::fct_inorder(Species)),
  hist = create_plot(data),
  fit = lm(Sepal.Width ~ Petal.Width + Species, data),
  report = rmarkdown::render(
    knitr_in("report.Rmd"),
    output_file = file_out("report.html"),
    quiet = TRUE
  )
)

plan
#> # A tibble: 5 x 2
#>   target   command                                                         
#>   <chr>    <chr>                                                           
#> 1 raw_data "readxl::read_excel(file_in(\"raw_data.xlsx\"))"                
#> 2 data     raw_data %>% mutate(Species = forcats::fct_inorder(Species))    
#> 3 hist     create_plot(data)                                               
#> 4 fit      lm(Sepal.Width ~ Petal.Width + Species, data)                   
#> 5 report   "rmarkdown::render(knitr_in(\"report.Rmd\"), output_file = file…

In this PR, the command column is now a list of language objects by default. drake still understands character columns, and wildcard functions still work.

library(drake)
plan <- drake_plan(
  raw_data = readxl::read_excel(file_in("raw_data.xlsx")),
  data = raw_data %>%
    mutate(Species = forcats::fct_inorder(Species)),
  hist = create_plot(data),
  fit = lm(Sepal.Width ~ Petal.Width + Species, data),
  report = rmarkdown::render(
    knitr_in("report.Rmd"),
    output_file = file_out("report.html"),
    quiet = TRUE
  )
)

plan
#> # A tibble: 5 x 2
#>   target   command                                                         
#>   <chr>    <S3: langs>                                                     
#> 1 raw_data readxl::read_excel(file_in("raw_data.xlsx"))                   …
#> 2 data     raw_data %>% mutate(Species = forcats::fct_inorder(Species))   …
#> 3 hist     create_plot(data)                                              …
#> 4 fit      lm(Sepal.Width ~ Petal.Width + Species, data)                  …
#> 5 report   rmarkdown::render(knitr_in("report.Rmd"), output_file = file_ou…

str(plan$command)
#> List of 5
#>  $ raw_data: language readxl::read_excel(file_in("raw_data.xlsx"))
#>  $ data    : language raw_data %>% mutate(Species = forcats::fct_inorder(Species))
#>  $ hist    : language create_plot(data)
#>  $ fit     : language lm(Sepal.Width ~ Petal.Width + Species, data)
#>  $ report  : language rmarkdown::render(knitr_in("report.Rmd"), output_file = file_out("report.html"),      quiet = TRUE)

Created on 2019-02-02 by the reprex package (v0.2.1)

Note <S3: langs> in the above tibble. Until r-lib/pillar#34 is solved, we have a custom print() method that deparses the commands before displaying them. This could be slow for large plans, but I think it is still worth being able to see the commands.

Related GitHub issues and pull requests

Checklist

  • I have read drake's code of conduct, and I agree to follow its rules.
  • I have listed any substantial changes in the development news.
  • I have added testthat unit tests to tests/testthat to confirm that any new features or functionality work correctly.
  • I have tested this pull request locally with devtools::check()
  • This pull request is ready for review.
  • I think this pull request is ready to merge.

@codecov-io
Copy link

codecov-io commented Feb 3, 2019

Codecov Report

Merging #708 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #708   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          72     72           
  Lines        5809   5841   +32     
=====================================
+ Hits         5809   5841   +32
Impacted Files Coverage Δ
R/utils-deprecate.R 100% <ø> (ø) ⬆️
R/api-mapreduce.R 100% <100%> (ø) ⬆️
R/test-testthat.R 100% <100%> (ø) ⬆️
R/api-plan.R 100% <100%> (ø) ⬆️
R/api-wildcards.R 100% <100%> (ø) ⬆️
R/utils-utils.R 100% <100%> (ø) ⬆️
R/vis-graphinfo.R 100% <100%> (ø) ⬆️
R/preprocess-sanitize.R 100% <100%> (ø) ⬆️
R/preprocess-codeanalysis.R 100% <100%> (ø) ⬆️
R/exec-standardize.R 100% <100%> (ø) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a5c5d66...24756bb. Read the comment docs.

@wlandau wlandau merged commit 9c63d62 into master Feb 3, 2019
@wlandau wlandau deleted the 700 branch February 3, 2019 04:27
@wlandau
Copy link
Collaborator Author

wlandau commented Feb 3, 2019

FYI: I updated the type summary. <S3: langs> was too obtuse, so I changed it to <expr>.

plan <- drake_plan(
  raw_data = readxl::read_excel(file_in("raw_data.xlsx")),
  data = raw_data %>%
    mutate(Species = forcats::fct_inorder(Species)),
  hist = create_plot(data),
  fit = lm(Sepal.Width ~ Petal.Width + Species, data),
  report = rmarkdown::render(
    knitr_in("report.Rmd"),
    output_file = file_out("report.html"),
    quiet = TRUE
  )
)
plan
#> # A tibble: 5 x 2
#>   target   command                                                         
#>   <chr>    <expr>                                                          
#> 1 raw_data readxl::read_excel(file_in("raw_data.xlsx"))                   …
#> 2 data     raw_data %>% mutate(Species = forcats::fct_inorder(Species))   …
#> 3 hist     create_plot(data)                                              …
#> 4 fit      lm(Sepal.Width ~ Petal.Width + Species, data)                  …
#> 5 report   rmarkdown::render(knitr_in("report.Rmd"), output_file = file_ou…

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

Successfully merging this pull request may close these issues.

None yet

4 participants