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

session_info() fails when info is a character vector with length > 1 #96

Closed
pollysummers opened this issue Feb 22, 2024 · 0 comments · Fixed by #104
Closed

session_info() fails when info is a character vector with length > 1 #96

pollysummers opened this issue Feb 22, 2024 · 0 comments · Fixed by #104
Labels
bug an unexpected problem or unintended behavior tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day

Comments

@pollysummers
Copy link

pollysummers commented Feb 22, 2024

The info argument of session_info() is supposed to be "auto", "all", or a character vector specifying which types of information to include.

#' @param info What information to show, it can be `"auto"` to choose
#' automatically, `"all"` to show everything, or a character vector
#' with elements from:
#' * `"platform"`: show platform information via [platform_info()],
#' * `"packages"`: show package information via [package_info()],
#' * `"python"`: show Python configuration via [python_info()],
#' * `"external"`: show information about external software, via
#' [external_info()].

But it actually produces an error if called with a character vector with length greater than one. For example:

library(sessioninfo);
session_info(info=c("packages","external"))
#> Error in info != "auto" && info != "all": 'length = 2' in coercion to 'logical(1)'

Created on 2024-02-22 with reprex v2.1.0

It's because of this && in the if-statement in line 61. info != "auto" and info != "all" are vectors with the same length as info, but the && operator doesn't accept vectors with more than one element.

if (missing(info)) info <- "auto"
choices <- c("platform", "packages", "python", "external")
if (info != "auto" && info != "all") {
info <- match.arg(info, choices, several.ok = TRUE)
}
if ("all" %in% info) {
info <- choices
} else if ("auto" %in% info) {
info <- c(
"platform",
"packages",
if (should_show_python(pkgs)) "python"
)
}

I'm not sure what the simplest/safest fix is... Some options:

  • if (!identical(info, "auto") & !identical(info, "all")) works.
  • if (length(info) == 1 && info != "auto" && info != "all") also works, because then it only does the && if the length is one.
  • It might make more sense to rearrange the flow and deal with the "any" %in% info and "all" %in% info cases first?
@gaborcsardi gaborcsardi added the bug an unexpected problem or unintended behavior label Feb 22, 2024
@gaborcsardi gaborcsardi added the tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day label Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants