Link: R
Update R, install packages and check version
Check R version
## Check R version
R.version
## Check R home path
R.home()
Update R in R GUI
install.pacakges("installr")
require("installr")
updateR()
Error handling
If encounter security issues:
- Disable secure download setting by: Uncheck “Use secure download method for HTTP”
- Use below argument to install and update R in R GUI
install.packages("installr",dependencies = TRUE, repos = 'cran.rstudio.com/') ## Then update by specifying the cran repo installr::updateR(cran_mirror = "cran.rstudio.com/")
(Optional) Change library path
Add following to RProfile
:
myPaths <- .libPaths() # get the paths
myPaths <- c(myPaths[2], myPaths[1]) # switch them
.libPaths(myPaths) # reassign them
From www.accelebrate.com/library/how-to-articles/r-rstudio-library
Install R packages
install_packages(c("tidyverse", "openxlsx"))
How to install tinytex offline
## From <community.rstudio.com/t/cant-install-tinytex-properly-via-install-prebuilt/28476>
tinytex::install_tinytex
tinytex:::install_prebuilt("install.zip")
tinytex:::is_tinytex()
Check installed packages
## From <stackoverflow.com/questions/38481980/get-the-list-of-installed-packages-by-user-in-r>
x <- installed.packages(); x[ is.na(x[,"Priority"]), c("Package", "Version")]
Close all data view windows in RStudio
CloseViews <- function(){
cmd <- paste0('wmctrl -c "Data:" -v')
ok <- TRUE
while(ok){
out <- suppressWarnings(system(cmd,intern=TRUE,ignore.stderr=TRUE))
Sys.sleep(0.2)
ok <- is.null(attr(out,"status"))
print(ok)
}
}
Then CloseViews() does the trick, which I found particularly helpful when working interactively.
From <stackoverflow.com/questions/14349868/programmatically-close-the-window-created-by-viewx>
Purl: convert R Markdown to R Script
knitr::purl("purl.Rmd")
From <bookdown.org/yihui/rmarkdown-cookbook/purl.html>
Convert backslash for Windows system
Copy file path, then run:
gsub("\\\\", "/", readClipboard())
Best practice: reduce the number of objects
The way is to create dataframe list.
dl <- list("f21" = df, "month" = df_month)
rm(df, df_month) ## to keep it clean
When refer object from dataframe list:
dl$f21
dl[['f21']]
dl[[1]]