Issue with pkg `rstudioapi` after updating to R 4.4
I'm seeing an issue that is new when using the reprex-package. This problem first occurred after updating to R 4.4.0.
My setup is VSCode 1.88.1, Windows 11, R 4.4.0 (64 bit).
Code:
reprex::reprex('data(diamonds, package = "ggplot2")')
Output:
"data(diamonds, package = \"ggplot2\")"
#> [1] "data(diamonds, package = \"ggplot2\")"
Error:
ℹ Rendering reprex...
Error in .make_numeric_version(x, strict, .standard_regexps()$valid_numeric_version) :
invalid non-character version specification 'x' (type: double)
> reprex::reprex('data(diamonds, package = "ggplot2")')
ℹ Rendering reprex...
Error in .make_numeric_version(x, strict, .standard_regexps()$valid_numeric_version) :
invalid non-character version specification 'x' (type: double)
> traceback()
9: stop(msg, domain = NA)
8: .make_numeric_version(x, strict, .standard_regexps()$valid_numeric_version)
7: numeric_version(0) at rstudioapi.R#237
6: rstudioapi::versionInfo()
5: is_rstudio_server()
4: reprex_clipboard()
3: expose_reprex_output(reprex_file, rtf = (venue == "rtf"))
2: reprex_impl(x_expr = substitute(x), input = input, wd = wd, venue = venue,
render = render, new_session = TRUE, advertise = advertise,
session_info = session_info, style = style, html_preview = html_preview,
comment = comment, tidyverse_quiet = tidyverse_quiet, std_out_err = std_out_err,
outfile = outfile)
1: reprex::reprex("data(diamonds, package = \"ggplot2\")")
Seems like rstudioapi::versionInfo() causes the error here:
The reprex package maintainer believe it's related to the VSCode R extension:
I think it's this in their rstudioapi shims. Your backtrace seems to be identifying the call is from the shim: 7: numeric_version(0) at rstudioapi.R#237
(https://github.com/tidyverse/reprex/issues/462)
I have encountered the same issue. This has to do with the VSCode R extension as there is no issue in R term launched in cmd.exe. It seems like the extension is not loading the global Rprofile properly, either.
I'm seeing the same on macOS (so not a Windows issue).
As I read the error message, it may be related to the fact that the version of R has been upgraded to make the comparison of numbers and version numbers an error.
Yes, .make_numeric_version() has changed quite a lot from 4.3.3 to 4.4.0 so the shim doesn't work any more. I can make R issue a warning instead of throwing an error by doing this in the session before running reprex::reprex():
Sys.setenv("_R_CHECK_STOP_ON_INVALID_NUMERIC_VERSION_INPUTS_" = "false")
Running the reprex:
r$> reprex::reprex(1+1)
ℹ Rendering reprex...
Warning in .make_numeric_version(x, strict, .standard_regexps()$valid_numeric_version) :
invalid non-character version specification 'x' (type: double)
✔ Reprex output is on the clipboard.
Result:
1 + 1
#> [1] 2
Created on 2024-05-03 with reprex v2.1.0