Skip to content

Rprofile #8

@ShixiangWang

Description

@ShixiangWang
options(encoding = 'UTF-8')
# options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))
# options(BioC_mirror="https://mirrors.tuna.tsinghua.edu.cn/bioconductor")
#Sys.setenv(XML_CONFIG="/usr/local/include/libxml2")
Sys.setenv(LANGUAGE = 'en')

options(languageserver.formatting_style = function(options) {
  style <- styler::tidyverse_style(indent_by = options$tabSize)
  style$token$force_assignment_op <- NULL
  style
})


#--------------------------------------------
# Set custom library and temp directory for R
# NOTE: please only change following 2 paths
#   Any Question, please email to
#       Shixiang Wang <w_shixiang@163.com>
#--------------------------------------------
.CUSTOM_LIB = "/Users/wsx/R_library" # set your custom library location
#.TMP = "C:/Tools/R/Rtmp"             # set a temp dir for R running
# please do not add '/' at the end !!!

if (!dir.exists(.CUSTOM_LIB)){
  dir.create(.CUSTOM_LIB)
}

.libPaths(c(.CUSTOM_LIB, .libPaths()))
message("Using library: ", .libPaths()[1])


# if(dirname(tempdir()) != .TMP){
#   if(!dir.exists(.TMP)) dir.create(.TMP)
#   cat(paste0("TMPDIR = ", .TMP), file="~/.Renviron", sep = "\n")
# }
# message("Using temp directory: ", .TMP)

#---------------------------------------------------
# pacman is optional, you can delete following code
# If you wanna use pacman, please read:
#   <https://www.jianshu.com/p/cb16ded75672>
# Basically,
# #1, you can use 'p_load' to load multiple package into R
#       like p_load(data.table, dplyr)
# #2, you can use 'p_get' just to install package
# #3, you can use 'p_update' to update all packages
#---------------------------------------------------
if(!require(pacman)){
  install.packages("pacman", dependencies = TRUE)
}
library(pacman)
# https://github.com/mikldk/roxytest
library(roxytest)

source(file.path(if (.Platform$OS.type == "windows") file.path(Sys.getenv("HOMEDRIVE"), Sys.getenv("HOMEPATH")) else Sys.getenv("HOME"), ".vscode-R", "init.R"))

# 使用清华镜像源
options(BioC_mirror="https://mirrors.tuna.tsinghua.edu.cn/bioconductor")

.loopInstall = function(pkg) {
  Sys.sleep(1)
  tryCatch(
    {
      message("=> Try installing ", pkg)
      remotes::install_github(pkg)
    },
    error = function(e) {
      .loopInstall(pkg)
    }
  )
}

.browseOnce <- function() {
  old <- getOption("error")
  function() {
    options(error = old)
    browser()
  }
}

options(error = .browseOnce)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions