Skip to content

Instantly share code, notes, and snippets.

@fcsest
Last active April 20, 2022 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fcsest/010bf225e862813321e0f41d24d04723 to your computer and use it in GitHub Desktop.
Save fcsest/010bf225e862813321e0f41d24d04723 to your computer and use it in GitHub Desktop.
My Rprofile for development in VSCode.
# setting options
options(width = 80)
# we set the cloud mirror, which is "network-close" to everybody, as default
local({
r <- getOption("repos")
r["CRAN"] <- "https://cloud.r-project.org"
options(repos = r)
})
# setup packages for development
if (interactive()) {
if (Sys.getenv("TERM_PROGRAM") == "vscode") {
# obtain list of packages in system library currently
lib_packages <- names(utils::installed.packages()[, 3])
if (!"remotes" %in% lib_packages) {
message("installing remotes package")
utils::install.packages("remotes")
}
if (!"renv" %in% lib_packages) {
message("installing renv package")
remotes::install_github("rstudio/renv@0.15.4-22")
}
if (!"jsonlite" %in% lib_packages) {
message("installing jsonlite package")
remotes::install_github("jeroen/jsonlite@v1.8.0")
}
if (!"rlang" %in% lib_packages) {
message("installing rlang package")
remotes::install_github("r-lib/rlang@v1.0.2")
}
if (!"rstudioapi" %in% lib_packages) {
message("installing rstudioapi package")
remotes::install_github("rstudio/rstudioapi@0.13")
}
if (!"vscDebugger" %in% lib_packages) {
message("installing vscDebugger package")
remotes::install_github("ManuelHentschel/vscDebugger@v0.4.7")
}
if (!"prompt" %in% lib_packages) {
message("installing prompt package")
remotes::install_github("gaborcsardi/prompt@v1.0.1")
}
if (!"usethis" %in% lib_packages) {
message("installing usethis package")
remotes::install_github("r-lib/usethis@v2.1.5")
}
if (!"devtools" %in% lib_packages) {
message("installing devtools package")
remotes::install_github("r-lib/devtools@v2.4.3")
}
if (!"languageserver" %in% lib_packages) {
message("installing languageserver package")
remotes::install_github("REditorSupport/languageserver@v0.3.12")
}
if (!"languageserver" %in% lib_packages) {
message("installing languageserver package")
remotes::install_github("REditorSupport/languageserver@v0.3.12")
}
if (!"httpgd" %in% lib_packages) {
message("installing httpgd package")
remotes::install_github("nx10/httpgd")
}
options(vsc.rstudioapi = TRUE)
}
# attach R terminal to VSCode
ifelse(
.Platform$OS.type == "windows",
"USERPROFILE",
"HOME"
) |>
Sys.getenv() |>
file.path(
".vscode-R",
"init.R"
) |>
source()
# Change console prompt line
prompt::set_prompt(prompt::prompt_fancy)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment