Skip to content

code_theme_default() errors when in RStudio, but without {rstudioapi} #697

@dgkf-roche

Description

@dgkf-roche

code_theme_default() uses is_rstudio() (by way of rstudio_detect) to determine whether to theme the output for RStudio. This correctly discovers that one is in RStudio, but then assumes that one must have rstudioapi available to load.

This is often not the case. Especially when a project uses renv - only packages relevant to the project will be included in the local library. This results in an error when trying to display .Last.error

# Error:                                                                                       
# ! error in pak subprocess
# Caused by error in `verify_extracted_package(filename, pkg_cache)`:
# ! /tmp/RtmpLAlqvr/file158119387aa7/src/contrib/x86_64-pc-linux-gnu-ubuntu-20.04/4.2/fastglm_0.0.3.tar.gz is not a valid binary, it is missing fastglm/Meta/package.rds.
# Type .Last.error to see the more details.
> .Last.error
# Error in loadNamespace(x) : there is no package called ‘rstudioapi’

Perhaps this condition should also check whether requireNamespace("rstudioapi", quietly = TRUE)

cli/R/prettycode.R

Lines 239 to 244 in 71fd2a5

rs <- rstudio_detect()
if (rs$type %in% c("rstudio_console", "rstudio_console_starting")) {
opt <- code_theme_opt("cli.code_theme_rstudio")
if (!is.null(opt)) return(opt)
code_theme_default_rstudio()
} else {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions