Some housekeeping commands in R

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’)
library(updateR)A new version R of 4.2.0 is available for update!
run updateR() to get the latest R on your macOS!

Checking the version of a package

packageVersion(“ggplot2”)
[1] ‘3.3.6’

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)
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.1
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
locale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other 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.7
loaded 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

detach("package:pryr", unload=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')

Change default language

Sys.setenv(LANG = 'es') #espagñol
Sys.setenv(LANG = 'fr') #français

Print working directory

getwd()#To changesetwd('folder path')

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store