Installing R, R Packages and Rstudio Instructions and Resources for New Users and Students

Installing R, R Packages and Rstudio Instructions and Resources for New Users and Students

Installing R, R packages and RStudio Instructions and Resources for new users and students Bruce Dudek 2021-07-27 Contents 1 Introduction 2 2 What is R? What is RStudio? 2 3 Why R? 2 4 Why not just spreadsheets? 3 5 What are “packages”? 3 6 Installing R 4 6.1 Major installation methods . .4 6.2 64 bit vs 32 bit installations . .4 7 Installing RStudio 4 8 Testing your R and R studio installations 4 9 Adding packages to your R installation 7 9.1 Installing packages from the command line . .7 9.2 Install more than one package at a time . .7 9.3 Install packages from the menus in RGui/Rconsole. .7 9.4 Install packages from the “Packages” tab in the RStudio pane (usually bottom right) . .8 9.5 Installing packages from GitHub . .8 9.6 Install many packages for use in B. Dudek’s course . .8 9.7 Installing the tidyverse . .8 9.8 Source vs binary package installation methods . .9 9.9 The Rcmdr package . .9 9.9.1 Configuring R Commander capability on MAC OS . .9 9.9.2 Some features and quirks of R Commander usage . 10 10 RTools for Windows 10 11 The bcdstats package and Installing packages from a locally saved file 10 12 The Bioconductor repository 11 13 Updating R, RStudio and R Packages 11 13.1 Updating/installing new R versions . 11 13.2 Updating R packages. 11 1 13.2.1 Updating packages from within base R . 11 13.2.2 Updating packages from within RStudio . 12 13.2.3 Updating tidyverse packages . 12 13.3 Updating RStudio . 12 14 Reproducibility 12 15 R Resources 12 1 Introduction This document provides information for new R users on installation, updating and maintining an R installation. It can be broadly useful to a wide audience, but is intended for students in B. Dudek’s statistics classes, and serves as the first of several R tutorial documents. Topics covered include installation/updates/maintenance of R, RStudio, and R packages. Some general background is provided along with instructions and links to detailed web postings that go into more detail if needed. 2 What is R? What is RStudio? The R programming language (https://www.r-project.org/) has major strengths in data management, statistical analysis and data visualization. It has fast become a primary tool for data scientists, statisticians and researchers. It can be used on multiple operating systems and its installation is largely straight forward on all platforms. As an open source and free software ecosystem it provides a rich array of tools for a diverse audience of users. This link to a page on the R project web site gives a more detailed overview: https://www.r-project.org/ab out.html Downloads of R and more information are found on CRAN (Comprehenisive R Archive Network): https: //cran.r-project.org/ R is installed as a relatively minimal configuration where the user passes R code to a command line environment called the R console (inside the R GUI). A majority of R users employ additional tool, RStudio (https://rstudio.com/) that is an Integrated Development Environment. Embedded in the RStudio configuration is the R console, file management and code writing capability, and several other useful components for displaying figures, managing add-on packages, etc. It is a very powerful way to use R, especially with its capabilities to use markdown, to build packages, and many other add-in capabilities. It is strongly recommended that new users become familiar with using RStudio very early in the R learning curve. 3 Why R? The question of why R? is often posed in the context of comparing it to other programming languages that can handle data science needs, or in comparison to commercially available software that have long and established histories (e.g., SAS, STATA, SPSS). There is no need to dwell on these comparisons. The major utility of R is its rich array of add-on contributions in the form of packages created by statisticians around the world. New methods can appear very quickly in the R eco-system of add-on packages. There is also an extensive support community online in the form of forums, blogs, and help sites. For the scientific researcher in many disciplines, skills in R are becoming an expected part of training in degree programs. It is an important tool to add to an arsenal of data analytic capabilities. These URL’s expand on the points made above: https://www.burns-stat.com/documents/tutorials/why-use-the-r-language/ http://www.econometricsbysimulation.com/2014/03/why-use-r-five-reasons.html 2 4 Why not just spreadsheets? Spreadsheets such as Excel have major positive features and are often very helpful for data entry and initial data management. But R can do these things well too, and there is a reproducibility element with R that is important, since code can be saved, repeated, and documented. At its core, R is a complete data management and analytic system, with far more capabilities than spreadsheets. See the following commentary for additional perspectives: https://www.burns-stat.com/documents/tutorials/spreadsheet-addiction/ 5 What are “packages”? The R language is very broadly capable, even in its simple original installation, but additional capabilities are found in add-on packages. These packages are created by statisticians/programmers world-wide and this is a major strength of the R ecosystem. The core R installation already has a set of add-on packages with capabilities suggested by their names. These are found in a sub-folder of the R program installation called src/library/: • base • compiler • datasets • graphics • grDevices • grid • methods • parallel • splines • stats • stats4 • tcltk • tools • translations • utils The R Project also “recommends” a set of additional packages that the user will have to install separately (see a later section in this document): https://cran.r-project.org/src/contrib/4.2.0/Recommended/ • KernSmooth • MASS • Matrix • boot • class • cluster • codetools • foreign • lattice • mgcv • nlme • nnet • rpart • spatial • survival These are all useful but most users will quickly compile a longer list of additional packages that they use for 3 specific purposes. For example the psych package contains a large suite of functions useful to researchers in the psychological sciences. Methods for installing these packages and a recommended set are described in a later section. 6 Installing R For purposes of B. Dudek’s classes, it is useful to install the most recent version of R so that we are all using the same version. As of this writing that version is 4.1, but it will likely be a later version by the time you read this. Also as of version 4.0, all previous packages you may have used on an earlier version need to be re-installed (see the section below). 6.1 Major installation methods On each of the major platforms, the base R installation occurs with a minimum of effort. The steps are: 1. Go to the R-project.org site, https://www.r-project.org/, and in the download section navigate with the CRAN link. This takes you to a page with a set of CRAN mirrors. Choose one. 2. Choose your operating system and then on the next page choose “base” which leads to a download. 3. Complete the download to your device and run the installer that was downloaded. Choose the default options at each point. Historically, I used to provide a detailed document with screen captures showing each step but it is so simple that it is no longer necessary to generate that level of detail. If you want more detail, go to one of these sites that do provide additional guidance: https://www.andrewheiss.com/blog/2012/04/17/install-r-rstudio-r-commander-windows-osx/ https://techvidvan.com/tutorials/install-r/ https://rstudio-education.github.io/hopr/starting.html https://www.datacamp.com/community/tutorials/installing-R-windows-mac-ubuntu https://www.dataquest.io/blog/tutorial-getting-started-with-r-and-rstudio/ 6.2 64 bit vs 32 bit installations On Windows platforms, both 32 bit and 64 bit R is installed by the procedures outlined above if you are using an x64 version of Windows (which by now, most all users are). The 32 bit version was created originally because older PC OS installations were only 32 bit - and there is a memory limitation that is now much higher in the 64 bit version. The 64 bit version is the one you will want to use. Soon, the R consortium will terminate offering a 32 bit version. On MAC OS and LINUX, the base R installation is 64 bit. 7 Installing RStudio After you have installed R, then install RStudio. Go to the RStudio web site https://rstudio.com/ and choose the download button (or go directly to the download page (https://rstudio.com/products/rstudio/download/). Then download the free RStudio Desktop version for your operating system. Execute the installer that you downloaded. 8 Testing your R and R studio installations In order to begin learning to use R and RStudio and test the installations, I suggest the following. 4 1. Open the 64 bit version of R that you installed (not RStudio at this point). It should look like this in Microsoft Windows and something similar in MAC OS: Figure 1: R Console inside the R GUI 2. At the command prompt in R Console, type the following to obtain the square root of 25: 25ˆ.5 ## [1] 5 R has returned an “object” that contains one element and that first element is the numeric value of the answer.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    13 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us