Some housekeeping commands in R
- Checking date and time
- Checking the version of R
- Update R
- Checking the version of a package
- Get the list of all outdated packages
- Checking all the functions in a package
- Update packages
- Restart the studio
- Get the list of the currently loaded packages
- Unload a package
- Unload all packages
- Check the conflicting packages/commands
- List all objects in the environment
- Remove all objects in the environment
- Print command history
- Change default language
- Print/Change working directory
- Turning off scientific notation
Checking date and time
date()
[1] “Sun Jun 4 21:03:52 2022”
Checking the version of R
R.version# the outputplatform x86_64-apple-darwin17.0
arch x86_64
os darwin17.0
system x86_64, darwin17.0
status
major 4
minor 1.2
year 2021
month 11
day 01
svn rev 81115
language R
version.string R version 4.1.2 (2021-11-01)
nickname Bird Hippie
Update R
library(devtools)install_github(‘andreacirilloac/updateR’)
Now run library
library(updateR)A new version R of 4.2.0 is available for update!
run updateR() to get the latest R on your macOS!
(Not tested on Windows)
Checking the version of a package
packageVersion(“ggplot2”)
[1] ‘3.3.6’
Checking all the functions of a package currently loaded
ls('package:plyr')
Get the list of all outdated packages
old.packages()
Update packages
update.packages()
Check size of a df in memory
library(pryr)
pryr::object_size(df)
Examples
df= iris
pryr::object_size(df)7,200 Bdf <- iris %>% select(5)
pryr::object_size(df)1,872 B
Restart the studio
.rs.restartR()
Check R version and all the loaded packages:
sessionInfo()R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.2.1Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dyliblocale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8attached base packages:
[1] stats graphics grDevices utils datasets methods baseother attached packages:
[1] pryr_0.1.5 magrittr_2.0.3 stringr_1.4.0 purrr_0.3.4 tidyr_1.2.0
[6] dplyr_1.0.9 tidyxl_1.0.7loaded via a namespace (and not attached):
[1] NLP_0.2-1 Rcpp_1.0.8.3 lobstr_1.1.1 pillar_1.7.0
[5] compiler_4.1.2 cellranger_1.1.0 WriteXLS_6.4.0 tokenizers_0.2.1
[9] tools_4.1.2 digest_0.6.29 evaluate_0.15 lifecycle_1.0.1
[13] tibble_3.1.7 lattice_0.20-45 pkgconfig_2.0.3 rlang_1.0.2
[17] Matrix_1.4-1 rstudioapi_0.13 DBI_1.1.2 cli_3.3.0
[21] yaml_2.3.5 writexl_1.4.0 parallel_4.1.2 xfun_0.30
[25] fastmap_1.1.0 knitr_1.38 janeaustenr_0.1.5 xml2_1.3.3
[29] generics_0.1.2 vctrs_0.4.1 rprojroot_2.0.3 grid_4.1.2
[33] tidyselect_1.1.2 here_1.0.1 glue_1.6.2 R6_2.5.1
[37] fansi_1.0.3 readxl_1.4.0 rmarkdown_2.13 codetools_0.2-18
[41] htmltools_0.5.2 SnowballC_0.7.0 ellipsis_0.3.2 assertthat_0.2.1
[45] tidytext_0.3.2 utf8_1.2.2 stringi_1.7.6 slam_0.1-50
[49] tm_0.7-8 crayon_1.5.1
Unload a package (using base R)
detach("package:pryr", unload=T)
Unload all packages (using pacman)
pacman::p_unload(pacman::p_loaded(), character.only = T))
Check the conflicting packages
conflicts()#with detailsconflicts(detail = T)
List all objects in the environment
ls()
Remove all objects in the environment
rm(list = ls())
Printing command history
savehistory('rCommands')
rCommands <- scan('file','char')
Now run the file name rCommands
to get the print of commands.
Change default language
Sys.setenv(LANG = 'es') #espagñol
Sys.setenv(LANG = 'fr') #français
Print working directory
getwd()#To changesetwd('folder path')
Turn off scientific notation
options(scipen = 999)
Happy housekeeping!