diff --git a/tests/testthat/_snaps/rix_init/append_Rprofile.txt b/tests/testthat/_snaps/rix_init/append_Rprofile.txt index e384bfd6..67fcb501 100644 --- a/tests/testthat/_snaps/rix_init/append_Rprofile.txt +++ b/tests/testthat/_snaps/rix_init/append_Rprofile.txt @@ -11,6 +11,8 @@ This is in the original Rprofile { is_rstudio <- Sys.getenv("RSTUDIO") == "1" is_nix_r <- nzchar(Sys.getenv("NIX_STORE")) + is_code <- Sys.getenv("TERM_PROGRAM") == "vscode" + is_positron <- Sys.getenv("POSITRON") == "1" if (isFALSE(is_nix_r) && isTRUE(is_rstudio)) { cat("{rix} detected RStudio R session") old_path <- Sys.getenv("PATH") @@ -38,5 +40,16 @@ This is in the original Rprofile .libPaths(new_paths) rm(current_paths, userlib_paths, user_dir, new_paths) } - rm(is_rstudio, is_nix_r) + if (isTRUE(is_code) && interactive() && isFALSE(is_rstudio) && isFALSE(is_positron)) { + vscode_r_init <- file.path(Sys.getenv(if (.Platform$OS.type == "windows") + "USERPROFILE" + else "HOME"), ".vscode-R", "init.R") + if (file.exists(vscode_r_init)) { + source(vscode_r_init) + } + else { + message("No .vscode-R/init.R file found. If you want to use VSCode-R, you need to source it in your .Rprofile or start vscode from within nix-shell") + } + } + rm(is_rstudio, is_nix_r, is_code, is_positron) } diff --git a/tests/testthat/_snaps/rix_init/golden_Rprofile.txt b/tests/testthat/_snaps/rix_init/golden_Rprofile.txt index 3b27e109..91774d0a 100644 --- a/tests/testthat/_snaps/rix_init/golden_Rprofile.txt +++ b/tests/testthat/_snaps/rix_init/golden_Rprofile.txt @@ -10,6 +10,8 @@ { is_rstudio <- Sys.getenv("RSTUDIO") == "1" is_nix_r <- nzchar(Sys.getenv("NIX_STORE")) + is_code <- Sys.getenv("TERM_PROGRAM") == "vscode" + is_positron <- Sys.getenv("POSITRON") == "1" if (isFALSE(is_nix_r) && isTRUE(is_rstudio)) { cat("{rix} detected RStudio R session") old_path <- Sys.getenv("PATH") @@ -37,5 +39,16 @@ .libPaths(new_paths) rm(current_paths, userlib_paths, user_dir, new_paths) } - rm(is_rstudio, is_nix_r) + if (isTRUE(is_code) && interactive() && isFALSE(is_rstudio) && isFALSE(is_positron)) { + vscode_r_init <- file.path(Sys.getenv(if (.Platform$OS.type == "windows") + "USERPROFILE" + else "HOME"), ".vscode-R", "init.R") + if (file.exists(vscode_r_init)) { + source(vscode_r_init) + } + else { + message("No .vscode-R/init.R file found. If you want to use VSCode-R, you need to source it in your .Rprofile or start vscode from within nix-shell") + } + } + rm(is_rstudio, is_nix_r, is_code, is_positron) }