18 Software
The current version of R (and any packages) used to make this document are
Code
sessionInfo()
## R version 4.5.0 (2025-04-11)
## Platform: x86_64-redhat-linux-gnu
## Running under: Fedora Linux 42 (Workstation Edition)
##
## Matrix products: default
## BLAS/LAPACK: FlexiBLAS OPENBLAS-OPENMP; LAPACK version 3.12.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## time zone: Europe/Berlin
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats graphics grDevices utils datasets compiler methods
## [8] base
##
## other attached packages:
## [1] colorout_1.3-2
##
## loaded via a namespace (and not attached):
## [1] Matrix_1.7-3 jsonlite_2.0.0 Rcpp_1.0.14
## [4] parallel_4.5.0 jquerylib_0.1.4 splines_4.5.0
## [7] yaml_2.3.10 fastmap_1.2.0 lattice_0.22-7
## [10] TH.data_1.1-3 R6_2.6.1 microbenchmark_1.5.0
## [13] knitr_1.50 htmlwidgets_1.6.4 MASS_7.3-65
## [16] tibble_3.3.0 bookdown_0.43 profvis_0.4.0
## [19] bslib_0.9.0 pillar_1.10.2 rlang_1.1.6
## [22] utf8_1.2.6 multcomp_1.4-28 cachem_1.1.0
## [25] xfun_0.52 sass_0.4.10 cli_3.6.5
## [28] magrittr_2.0.3 digest_0.6.37 grid_4.5.0
## [31] mvtnorm_1.3-3 sandwich_3.1-1 lifecycle_1.0.4
## [34] vctrs_0.6.5 bench_1.1.4 evaluate_1.0.4
## [37] glue_1.8.0 codetools_0.2-20 zoo_1.8-14
## [40] survival_3.8-3 profmem_0.7.0 rmarkdown_2.29
## [43] tools_4.5.0 pkgconfig_2.0.3 htmltools_0.5.8.1
With Rstudio, you can update both R and Rstudio.
18.1 Latest versions
Make sure R is up to date.
Make sure your R packages are up to date.
After updating R, you can update all packages stored in all .libPaths()
with the following command
Code
Tricks: Used Rarely:
To find specific broken packages after an update
Code
library(purrr)
set_names(.libPaths()) %>%
map(function(lib) {
.packages(all.available = TRUE, lib.loc = lib) %>%
keep(function(pkg) {
f <- system.file('Meta', 'package.rds', package = pkg, lib.loc = lib)
tryCatch({readRDS(f); FALSE}, error = function(e) TRUE)
})
})
# https://stackoverflow.com/questions/31935516/installing-r-packages-error-in-readrdsfile-error-reading-from-connection/55997765
To remove packages duplicated in multiple libraries
18.2 General Workflow
If you want to go further down the reproducibility route (recommended, but not required for our class), consider making your entire workflow use Free Open Source Software
Linux.
An alternative to windows and mac operating systems. Used in computing clusters, big labs, and phones. Ubuntu and Fedora are popular brands.
- https://www.r-bloggers.com/linux-data-science-virtual-machine-new-and-upgraded-tools/,
- http://www.howtogeek.com/249966/how-to-install-and-use-the-linux-bash-shell-on-windows-10/
On Fedora, you can open RStudio on the commandline with
Alternatively, you are encouraged to try using R without a GUI. E.g., on Fedora, this document can be created directly via
18.3 Sweave
Sweave is an alternative to Rmarkdown for integrating latex and R. While Rmarkdown “writes R and latex within markdown”, Sweave “write R in latex”. Sweave files end in “.Rnw” and can be called within R
or directly from the command line
In both cases, a latex file Sweavefile.tex
is produced, which can then be converted to Sweavefile.pdf
.
For more on Sweave,
18.4 Stata
For those transitioning from Stata or replicating others’ Stata work, you can work with Stata data and code within R.
Translations of common procedures is provided by https://stata2r.github.io/. See also the textbook “R for Stata Users” by Robert A. Muenchen and Joseph M. Hilbe.
Many packages allows you to read data created by different programs. As of right now, haven
is a particularly useful for reading in Stata files
You can also execute stata commands directly in R via package Rstata
. (Last time I checked, Rstata
requires you to have purchased a non-student version of Stata.) Moreover, you can include stata in the markdown reports via package Statamarkdown
:
There are many R packages to replicate or otherwise directly copy what Stata does. For example, see the margins
package https://cran.r-project.org/web/packages/margins/vignettes/Introduction.html
For more information on R and Stata, see
- https://github.com/lbraglia/RStata
- https://ignacioriveros1.github.io/r/2020/03/22/r_and_stata.html
- https://bookdown.org/yihui/rmarkdown-cookbook/eng-stata.html
- https://rpubs.com/quarcs-lab/stata-from-Rstudio
- https://clanfear.github.io/Stata_R_Equivalency/docs/r_stata_commands.html
- https://libguides.bates.edu/c.php?g=209169&p=7233333
You can also use other software (such as Python) within R. You can also use R within Stata, or both within Python. With R, you can easily import many different data types