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

Weird interaction with targets package #88

Closed
agila5 opened this issue Feb 24, 2023 · 2 comments
Closed

Weird interaction with targets package #88

agila5 opened this issue Feb 24, 2023 · 2 comments

Comments

@agila5
Copy link

agila5 commented Feb 24, 2023

Dear package developers, a few minutes ago I was running some code in a (private) project that uses the packages conflicted and targets (and several more packages) and I noticed a weird interaction between the two of them. The following (quite long, sorry...) code exhibits the problem.

If I run the problematic code without targets, I get an expected error which raised by conflicted:

library(conflicted)
library(spatstat)
#> Loading required package: spatstat.data
#> Loading required package: spatstat.geom
#> spatstat.geom 3.0-6
#> Loading required package: spatstat.random
#> spatstat.random 3.1-3
#> Loading required package: spatstat.explore
#> Loading required package: nlme
#> spatstat.explore 3.0-6
#> Loading required package: spatstat.model
#> Loading required package: rpart
#> spatstat.model 3.2-1
#> Loading required package: spatstat.linnet
#> spatstat.linnet 3.0-6
#> 
#> spatstat 3.0-3 
#> For an introduction to spatstat, type 'beginner'
library(scales)

rescale(simplenet)
#> Error:
#> ! [conflicted] rescale found in 2 packages.
#> Either pick the one you want with `::`:
#> * scales::rescale
#> * spatstat.geom::rescale
#> Or declare a preference with `conflicts_prefer()`:
#> * `conflicts_prefer(scales::rescale)`
#> * `conflicts_prefer(spatstat.geom::rescale)`

#> Backtrace:
#>     x
#>  1. \-conflicted (local) `<fn>`()
#>  2.   \-cli::cli_abort(...)
#>  3.     \-rlang::abort(...)

Created on 2023-02-24 with reprex v2.0.2

The same error occurs when conflicted is the last package I load. On other hand, when I run the previous code in a targets workflow, it looks like the conflicted package is ignored and I get another type of error (due to the fact that R runs scales::rescale instead of spatstat.geom::rescale):

library(targets)

tar_dir({
  tar_script(
    code = {
      tar_option_set(packages = c("conflicted", "spatstat", "scales"))
      list(
        tar_target(
          name = "ABC", 
          command = rescale(simplenet)
        )
      )
    }
  )
  tar_make()
})
#> * start target ABC
#> x error target ABC
#> * end pipeline [1.63 seconds]
#> Error:
#> ! Error running targets::tar_make()
#>   Error messages: targets::tar_meta(fields = error, complete_only = TRUE)
#>   Debugging guide: https://books.ropensci.org/targets/debugging.html
#>   How to ask for help: https://books.ropensci.org/targets/help.html
#>   Last error: no applicable method for 'rescale' applied to an object of class "c('linnet', 'list')"

#> Backtrace:
#>     x
#>  1. \-targets::tar_make()
#>  2.   \-targets:::callr_outer(...)
#>  3.     +-targets:::if_any(...)
#>  4.     \-targets:::callr_error(condition = out, fun = fun)
#>  5.       \-targets::tar_throw_run(message, class = class(condition))
#>  6.         \-targets::tar_error(...)
#>  7.           \-rlang::abort(message = message, class = class, call = tar_empty_envir)

Created on 2023-02-24 with reprex v2.0.2

The same does not occur when conflicted is the last loaded package:

library(targets)

tar_dir({
  tar_script(
    code = {
      tar_option_set(packages = c("spatstat", "scales", "conflicted"))
      list(
        tar_target(
          name = "ABC", 
          command = rescale(simplenet)
        )
      )
    }
  )
  tar_make()
})
#> * start target ABC
#> x error target ABC
#> * end pipeline [1.84 seconds]
#> Error:
#> ! Error running targets::tar_make()
#>   Error messages: targets::tar_meta(fields = error, complete_only = TRUE)
#>   Debugging guide: https://books.ropensci.org/targets/debugging.html
#>   How to ask for help: https://books.ropensci.org/targets/help.html
#>   Last error: [conflicted] rescale found in 2 packages.
#> Either pick the one you want with `::`:
#> * scales::rescale
#> * spatstat.geom::rescale
#> Or declare a preference with `conflicts_prefer()`:
#> * `conflicts_prefer(scales::rescale)`
#> * `conflicts_prefer(spatstat.geom::rescale)`

#> Backtrace:
#>     x
#>  1. \-targets::tar_make()
#>  2.   \-targets:::callr_outer(...)
#>  3.     +-targets:::if_any(...)
#>  4.     \-targets:::callr_error(condition = out, fun = fun)
#>  5.       \-targets::tar_throw_run(message, class = class(condition))
#>  6.         \-targets::tar_error(...)
#>  7.           \-rlang::abort(message = message, class = class, call = tar_empty_envir)

Created on 2023-02-24 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value
#>  version  R version 4.1.3 (2022-03-10)
#>  os       Windows 10 x64 (build 19044)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_United Kingdom.1252
#>  ctype    English_United Kingdom.1252
#>  tz       Europe/Berlin
#>  date     2023-02-24
#>  pandoc   2.19.2 @ D:/RStudio/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version date (UTC) lib source
#>  backports     1.4.1   2021-12-13 [1] CRAN (R 4.1.3)
#>  base64url     1.4     2018-05-14 [1] CRAN (R 4.1.3)
#>  callr         3.7.3   2022-11-02 [1] CRAN (R 4.1.3)
#>  cli           3.6.0   2023-01-09 [1] CRAN (R 4.1.3)
#>  codetools     0.2-18  2020-11-04 [2] CRAN (R 4.1.3)
#>  data.table    1.14.8  2023-02-17 [1] CRAN (R 4.1.3)
#>  digest        0.6.31  2022-12-11 [1] CRAN (R 4.1.3)
#>  evaluate      0.20    2023-01-17 [1] CRAN (R 4.1.3)
#>  fansi         1.0.4   2023-01-22 [1] CRAN (R 4.1.3)
#>  fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.1.3)
#>  fs            1.6.1   2023-02-06 [1] CRAN (R 4.1.3)
#>  glue          1.6.2   2022-02-24 [1] CRAN (R 4.1.3)
#>  htmltools     0.5.4   2022-12-07 [1] CRAN (R 4.1.3)
#>  igraph        1.4.0   2023-02-10 [1] CRAN (R 4.1.3)
#>  knitr         1.42    2023-01-25 [1] CRAN (R 4.1.3)
#>  lifecycle     1.0.3   2022-10-07 [1] CRAN (R 4.1.3)
#>  magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.1.3)
#>  pillar        1.8.1   2022-08-19 [1] CRAN (R 4.1.3)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.1.3)
#>  processx      3.8.0   2022-10-26 [1] CRAN (R 4.1.3)
#>  ps            1.7.2   2022-10-26 [1] CRAN (R 4.1.3)
#>  purrr         1.0.1   2023-01-10 [1] CRAN (R 4.1.3)
#>  R.cache       0.16.0  2022-07-21 [1] CRAN (R 4.1.3)
#>  R.methodsS3   1.8.2   2022-06-13 [1] CRAN (R 4.1.3)
#>  R.oo          1.25.0  2022-06-12 [1] CRAN (R 4.1.3)
#>  R.utils       2.12.2  2022-11-11 [1] CRAN (R 4.1.3)
#>  R6            2.5.1   2021-08-19 [1] CRAN (R 4.1.3)
#>  reprex        2.0.2   2022-08-17 [1] CRAN (R 4.1.3)
#>  rlang         1.0.6   2022-09-24 [1] CRAN (R 4.1.3)
#>  rmarkdown     2.20    2023-01-19 [1] CRAN (R 4.1.3)
#>  rstudioapi    0.14    2022-08-22 [1] CRAN (R 4.1.3)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.1.3)
#>  styler        1.9.0   2023-01-15 [1] CRAN (R 4.1.3)
#>  targets     * 0.14.2  2023-01-06 [1] CRAN (R 4.1.3)
#>  tibble        3.1.8   2022-07-22 [1] CRAN (R 4.1.3)
#>  tidyselect    1.2.0   2022-10-10 [1] CRAN (R 4.1.3)
#>  utf8          1.2.3   2023-01-31 [1] CRAN (R 4.1.3)
#>  vctrs         0.5.2   2023-01-23 [1] CRAN (R 4.1.3)
#>  withr         2.5.0   2022-03-03 [1] CRAN (R 4.1.3)
#>  xfun          0.37    2023-01-31 [1] CRAN (R 4.1.3)
#>  yaml          2.3.7   2023-01-23 [1] CRAN (R 4.1.3)
#> 
#>  [1] C:/Users/Andrea Gilardi/Documents/R/win-library/4.1
#>  [2] C:/Program Files/R/R-4.1.3/library
#> 
#> ------------------------------------------------------------------------------

I'm not sure if this is expected behaviour but I would say that, at least for me, this is quite surprising.

EDIT: The same error persists with the github version of the two packages.
EDIT2: I also opened a discussion in the targets repo: ropensci/targets#1026

@agila5
Copy link
Author

agila5 commented Feb 25, 2023

The maintainer of the targets package added more details and a solution on the discussion page. If you think that nothing should be changed here, feel free to close!

@hadley
Copy link
Member

hadley commented Feb 26, 2023

I don't think there's anything we can do here; conflicted is designed specifically for use in interactive sessions.

@hadley hadley closed this as completed Feb 26, 2023
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