2

我正在使用 RStudio 进行相关工作。直到昨天我决定试一试时,我一直忽略使用drake::make()提示。r_make()

现在,我有点苦恼。不知道我做了什么/如果我发现了一个错误。

我的项目计划不大,但目标构建很大(每个数据拉取 10-20 分钟)。make()我已经使用RStudio 控制台端到端运行它。一切都是最新的。即使我R在终端中打开一个单独的会话并运行outdated(),我也看不到任何过时的东西。

但是,r_make()从 Rstudio 控制台或R在单独的终端中运行会导致许多目标过时。

而且无论我运行多少次r_make(),这些对象都保持未更新。

终端运行-R

我不知道该怎么做。我想继续使用r_make(),但我卡住了。

更新

https://gitlab.com/rsangole/drake-test上的可重现示例

更新 2

运行@landau 的reprex示例,输出在这里。正如 Will 使用此脚本获得的那样,它工作正常:https ://gitlab.com/rsangole/drake-test/snippets/1894934

然而...

如果我在 RStudio 中以交互模式运行https://gitlab.com/rsangole/drake-test/blob/master/make.R ,我可以重现我的情况。重现:

  1. 打开新的 Rstudio,清理环境
  2. 在https://gitlab.com/rsangole/drake-test中下载可重现的示例
  3. 运行https://gitlab.com/rsangole/drake-test/blob/master/make.R
  4. 期望输出如https://gitlab.com/rsangole/drake-test/snippets/1894937

即使更新drake到最新的前沿版本后也会出现同样的问题

make.R如果我通过Rin运行,也能够复制问题,zsh从而完全绕过 RStudio。

4

2 回答 2

1

reprex我使用https://gitlab.com/rsangole/drake-test创建了一个,但我无法重现您所看到的内容。您使用drake的方式与下面的代码不同吗?

library(drake)

# Write script files

package_code <- quote({
  library(data.table)
  library(drake)
})

function_code <- quote(
  make_data <- function(download_date){
    data.table(
      dt = download_date,
      x = runif(n = 1e5),
      y = sample(letters,size = 1e5,replace = T)
    )
  }
)

plan_code <- quote(
  plan <- drake_plan(
    download_date = "2019-09-08",
    x = make_data(download_date)
  )
)

writeLines(deparse(package_code), "packages.R")
writeLines(deparse(function_code), "functions.R")
writeLines(deparse(plan_code), "plan.R")

# Run make()

source("packages.R")
source("functions.R")
source("plan.R")

make(
  plan,
  verbose = 2,
  parallelism = "future",
  jobs = 4L,
  lock_envir = FALSE
)
#> 
target download_date
#> 
target x

make(
  plan,
  verbose = 2,
  parallelism = "future",
  jobs = 4L,
  lock_envir = FALSE
)
#> 
All targets are already up to date.

config <- drake_config(plan)
outdated(config)
#> character(0)

# Write _drake.R

drake_code <- quote({
  source("packages.R")
  source("functions.R")
  source("plan.R")
  drake_config(
    plan, 
    verbose = 2, 
    jobs = 3L, 
    lock_envir = FALSE, 
    parallelism = "future"
  )
})

writeLines(deparse(drake_code), "_drake.R")

# Run r_make()

r_make()
#> 
#> ..
[34mAll targets are already up to date.[39m

r_make()
#> 
#> .
[34mAll targets are already up to date.[39m

r_outdated()
#> 
#> .
#> character(0)

reprex 包(v0.3.0)于 2019 年 9 月 13 日创建

devtools::session_info()
#> ─ Session info ──────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.6.1 (2019-07-05)
#>  os       Ubuntu 18.04.2 LTS          
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language                             
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       America/New_York            
#>  date     2019-09-13                  
#> 
#> ─ Packages ──────────────────────────────────────────────────────────────
#>  package     * version date       lib source        
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 3.6.1)
#>  backports     1.1.4   2019-04-10 [1] CRAN (R 3.6.1)
#>  base64url     1.4     2018-05-14 [1] CRAN (R 3.6.1)
#>  callr         3.3.1   2019-07-18 [1] CRAN (R 3.6.1)
#>  cli           1.1.0   2019-03-19 [1] CRAN (R 3.6.1)
#>  codetools     0.2-16  2018-12-24 [1] CRAN (R 3.6.1)
#>  crayon        1.3.4   2017-09-16 [1] CRAN (R 3.6.1)
#>  data.table  * 1.12.2  2019-04-07 [1] CRAN (R 3.6.1)
#>  desc          1.2.0   2018-05-01 [1] CRAN (R 3.6.1)
#>  devtools      2.2.0   2019-09-07 [1] CRAN (R 3.6.1)
#>  digest        0.6.20  2019-07-04 [1] CRAN (R 3.6.1)
#>  drake       * 7.6.1   2019-08-19 [1] CRAN (R 3.6.1)
#>  DT            0.8     2019-08-07 [1] CRAN (R 3.6.1)
#>  ellipsis      0.2.0.1 2019-07-02 [1] CRAN (R 3.6.1)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 3.6.1)
#>  filelock      1.0.2   2018-10-05 [1] CRAN (R 3.6.1)
#>  fs            1.3.1   2019-05-06 [1] CRAN (R 3.6.1)
#>  future        1.14.0  2019-07-02 [1] CRAN (R 3.6.1)
#>  globals       0.12.4  2018-10-11 [1] CRAN (R 3.6.1)
#>  glue          1.3.1   2019-03-12 [1] CRAN (R 3.6.1)
#>  highr         0.8     2019-03-20 [1] CRAN (R 3.6.1)
#>  htmltools     0.3.6   2017-04-28 [1] CRAN (R 3.6.1)
#>  htmlwidgets   1.3     2018-09-30 [1] CRAN (R 3.6.1)
#>  igraph        1.2.4.1 2019-04-22 [1] CRAN (R 3.6.1)
#>  knitr         1.24    2019-08-08 [1] CRAN (R 3.6.1)
#>  listenv       0.7.0   2018-01-21 [1] CRAN (R 3.6.1)
#>  magrittr      1.5     2014-11-22 [1] CRAN (R 3.6.1)
#>  memoise       1.1.0   2017-04-21 [1] CRAN (R 3.6.1)
#>  pillar        1.4.2   2019-06-29 [1] CRAN (R 3.6.1)
#>  pkgbuild      1.0.5   2019-08-26 [1] CRAN (R 3.6.1)
#>  pkgconfig     2.0.2   2018-08-16 [1] CRAN (R 3.6.1)
#>  pkgload       1.0.2   2018-10-29 [1] CRAN (R 3.6.1)
#>  prettyunits   1.0.2   2015-07-13 [1] CRAN (R 3.6.1)
#>  processx      3.4.1   2019-07-18 [1] CRAN (R 3.6.1)
#>  ps            1.3.0   2018-12-21 [1] CRAN (R 3.6.1)
#>  R6            2.4.0   2019-02-14 [1] CRAN (R 3.6.1)
#>  Rcpp          1.0.2   2019-07-25 [1] CRAN (R 3.6.1)
#>  remotes       2.1.0   2019-06-24 [1] CRAN (R 3.6.1)
#>  rlang         0.4.0   2019-06-25 [1] CRAN (R 3.6.1)
#>  rmarkdown     1.15    2019-08-21 [1] CRAN (R 3.6.1)
#>  rprojroot     1.3-2   2018-01-03 [1] CRAN (R 3.6.1)
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 3.6.1)
#>  storr         1.2.1   2018-10-18 [1] CRAN (R 3.6.1)
#>  stringi       1.4.3   2019-03-12 [1] CRAN (R 3.6.1)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 3.6.1)
#>  testthat      2.2.1   2019-07-25 [1] CRAN (R 3.6.1)
#>  tibble        2.1.3   2019-06-06 [1] CRAN (R 3.6.1)
#>  txtq          0.1.5   2019-08-19 [1] CRAN (R 3.6.1)
#>  usethis       1.5.1   2019-07-04 [1] CRAN (R 3.6.1)
#>  withr         2.1.2   2018-03-15 [1] CRAN (R 3.6.1)
#>  xfun          0.9     2019-08-21 [1] CRAN (R 3.6.1)
#>  yaml          2.2.0   2018-07-25 [1] CRAN (R 3.6.1)
#> 
#> [1] /home/landau/R/R-3.6.1/library

更新

reprex自己运行并发布结果:

reprex::reprex({
library(drake)

# Write script files

package_code <- c(
  "library(data.table)",
  "library(drake)"
)

function_code <- c(
  "make_data <- function(download_date){",
  "  data.table(",
  "    dt = download_date,",
  "    x = runif(n = 1e5),",
  "    y = sample(letters,size = 1e5,replace = T)",
  "  )",
  "}"
)

plan_code <- c(
  "plan <- drake_plan(",
  "  download_date = \"2019-09-08\",",
  "  x = make_data(download_date)",
  ")"
)

drake_code <- c(
  "source(\"packages.R\")",
  "source(\"functions.R\")",
  "source(\"plan.R\")",
  "drake_config(",
  "  plan,",
  "  verbose = 2,",
  "  jobs = 3L,",
  "  lock_envir = FALSE,",
  "  parallelism = \"future\",",
  "  console_log_file = \"r_make.log\"",
  ")"
)

writeLines(package_code, "packages.R")
writeLines(function_code, "functions.R")
writeLines(plan_code, "plan.R")
writeLines(drake_code, "_drake.R")

# Check that we wrote the scripts properly

cat(readLines("packages.R"), sep = "\n")

cat(readLines("functions.R"), sep = "\n")

cat(readLines("plan.R"), sep = "\n")

cat(readLines("_drake.R"), sep = "\n")

# Is there already .drake/ cache somewhere? 

list.files()

find_cache()


# If so, this reprex is not clean.

for (i in seq_len(10)) {
  clean(destroy = TRUE)
}

# Get ready

source("packages.R")
source("functions.R")
source("plan.R")
config <- drake_config(plan)

# Run make() and r_make()

make(
  plan,
  verbose = 2,
  parallelism = "future",
  jobs = 4L,
  lock_envir = FALSE,
  console_log_file = "make.log"
)

outdated(config)

r_make()

r_outdated()

make(
  plan,
  verbose = 2,
  parallelism = "future",
  jobs = 4L,
  lock_envir = FALSE,
  console_log_file = "make.log"
)

outdated(config)

r_make()

r_outdated()

# Check the log files to see what triggered the targets.

cat(readLines("make.log"), sep = "\n")

cat(readLines("r_make.log"), sep = "\n")
}, si = TRUE, venue = "so")

于 2019-09-14T01:42:38.810 回答
0

我发现了这个问题。我正在使用“2019-06-01”-ish 的 MRAN 快照。将所有软件包升级到 10 月 10 日的 MRAN 修复了所有问题。

于 2019-10-10T03:48:33.373 回答