15 Software
15.1 Latest versions
Make sure your packages are up to date
After reinstalling, you can update all packages stored in all .libPaths()
with the following command
To find broken packages after an update
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
15.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. E.g., 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
Latex: An alternative to Microsoft Word. Great for writing many equations and typesetting. Easy to integrate Figures, Tables, and References. Steep learning curve.
- easiest to get started online with Overleaf
- can also download yourself via Tex Live and GUI TexStudio
To begin programming, see
15.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 Sweave_file.tex
is produced, which can then be converted to Sweave_file.pdf
.
For more on Sweave,
- https://rpubs.com/YaRrr/SweaveIntro
- https://support.rstudio.com/hc/en-us/articles/200552056-Using-Sweave-and-knitr
- https://www.statistik.lmu.de/~leisch/Sweave/Sweave-manual.pdf
Knitr:
You can also produce a pdf from an .Rnw file via knitr
Rscript -e "knitr::Sweave2knitr('Sweave_file.Rnw')"
Rscript -e "knitr::knit2pdf('Sweave_file-knitr.Rnw')"
For background on knitr
15.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