{"id":51114,"date":"2011-11-14T14:06:04","date_gmt":"2011-11-14T19:06:04","guid":{"rendered":"http:\/\/www.bu.edu\/tech\/?page_id=51114"},"modified":"2024-08-16T13:40:27","modified_gmt":"2024-08-16T17:40:27","slug":"r-basics","status":"publish","type":"page","link":"https:\/\/www.bu.edu\/tech\/support\/research\/software-and-programming\/common-languages\/r-basics\/","title":{"rendered":"R"},"content":{"rendered":"<h2>Description<\/h2>\n<p>R is a language and environment for statistical computing and graphics. R provides a wide variety of statistical and graphical techniques and is highly extensible. Example analysis that can be done with R include linear and nonlinear modeling, classical statistical tests, time-series analysis, classification, and clustering.<\/p>\n<h2>Availability<\/h2>\n<p>R is free software under the GNU project and is available for Windows, macOS, and Linux systems. To install R on your local system, visit the <a href=\"https:\/\/www.r-project.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">R Project website<\/a> to download the installation files.<\/p>\n<p>On the SCC there are multiple versions of R available as modules. A complete list of R versions available can be found on the <a href=\"https:\/\/sccsvc.bu.edu\/software\/#\/package\/R\/\" target=\"_blank\" rel=\"noopener noreferrer\">R modules<\/a> summary page. One can also view this list inside a terminal connected to the SCC by executing the following command:<\/p>\n<pre><code class=\"code-block\" style=\"padding: 0em 1em 0em 1em;\"><span class=\"prompt\">scc1$<\/span> <span class=\"command\">module spider R<\/span><\/code><\/pre>\n<h2>Quick Start Guide to using R on the SCC<\/h2>\n<p>Below are two quick start guides for using R on the SCC and the third bullet point is a link to a video for a more detailed introduction to using R on the SCC.<\/p>\n<ul>\n<li><a href=\"#ONDEMAND\">Using OnDemand<\/a><\/li>\n<li><a href=\"#TERMINAL\">Starting R Console Within a Terminal<\/a><\/li>\n<li>&#8220;<a href=\"https:\/\/www.bu.edu\/tech\/support\/research\/training-consulting\/rcs-tutorial-videos-and-third-party-tutorials\/using-r\/\" target=\"_blank\" rel=\"noopener noreferrer\">Introduction to Using R and RStudio on the SCC<\/a>&#8221; (video)<\/li>\n<\/ul>\n<h3><a id=\"ONDEMAND\" name=\"ONDEMAND\"><\/a>Using OnDemand<\/h3>\n<ol>\n<li>Log on to the <a href=\"https:\/\/scc-ondemand.bu.edu\/\" target=\"_blank\" rel=\"noopener noreferrer\">SCC OnDemand Portal<\/a>. (See our <a href=\"https:\/\/www.bu.edu\/tech\/support\/research\/system-usage\/connect-scc\/scc-ondemand\/\">OnDemand page<\/a> to learn more about this portal).<\/li>\n<li>Click on <b>Interactive Apps<\/b> and then on <b>RStudio Server<\/b>.<br \/>\n        <img src=\"\/tech\/files\/2024\/08\/select_rstudio_6.gif\" alt=\"An animated GIF showing the SCC OnDemand home webpage. The mouse moves to the top menu bar and click on &quot;Interactive Apps&quot;. It then proceeds down the list of applications and clicks on &quot;RStudio Server&quot;. \"  width=\"500\" class=\"alignnone size-full wp-image-153755\" style=\"border: 1px solid;\" \/>\n        <\/li>\n<li>In the drop down menus select the latest version of RStudio and a version of R you wish to load. Additionally, specify number of hours and cores for the job.\n<div class=\"highlight-yellow\"><b>NOTE:<\/b> If you belong to more than one SCC project, select the appropriate project in the &#8220;Project&#8221; drop down menu at the bottom of the form.<\/div>\n<p><img src=\"\/tech\/files\/2024\/07\/Select_rstudio_and_rversion2.gif\" alt=\"An animated GIF showing the OnDemand job request form for RStudio Server. The mouse moves to the &quot;RStudio Version&quot; drop down menu and selects versions &quot;2024.04.2-764&quot;. The mouse then selects R version 4.4.0 for field &quot;R Version. Finally, the mouse moves down to the form to and clicks on &quot;Number of hours&quot; and &quot;Number of cores&quot; text fields. The default values of 12 hours and 1 core is left as is.\" width=\"500\" class=\"alignnone wp-image-153454 size-full\" style=\"border: 1px solid;\" \/><\/li>\n<li>Click <b>Launch<\/b> to submit the job request. Once the job status changes from <i>Queued<\/i> to <i>Running<\/i>, click <b>Connect to RStudio Server<\/b> button to connect to the RStudio session.<br \/>\n<img src=\"\/tech\/files\/2024\/07\/Connect_to_rstudio.gif\" alt=\"An animated GIF showing the SCC OnDemand job request for for RStudio Server. The form is already filled out, the mouse scrolls the page down to the bottom of the form and clicks on &quot;Launch&quot;. The page changes to the &quot;My Interactive Session&quot; page where the RStudio Server job just submitted is shown to be in the &quot;Queued&quot; state. The job state changes to &quot;Starting&quot; and then &quot;Running&quot;. The mouse then moves to the &quot;Connect to RStudio Server&quot; button and clicks it. The page then changes showing the RStudio Server page.\" width=\"500\" class=\"alignnone wp-image-153444 size-full\" style=\"border: 1px solid;\" \/><\/li>\n<li>After connecting to the RStudio session, set your working directory to the appropriate SCC project directory using <b>setwd()<\/b> function. Then set the &#8220;File&#8221; pane to the working directory by clicking the blue gear icon and click &#8220;Go to working directory&#8221;.<br \/>\n<img src=\"\/tech\/files\/2024\/08\/setworking_dir2.gif\" alt=\"An animated GIF showing the bottom half of the RStudio Server window, with the &quot;console&quot; tab showing on the left pane and the &quot;Files&quot; tab showing on the right pane. The mouse moves to the Console pane and click on the prompt. Then the command 'setwd(&quot;\/projectnb\/scv\/milechin\/r_code\/&quot;)' is executed to set the working directory. The mouse then moves to the &quot;Files&quot; pane on the right and clicks on the blue gear icon and from the menu selects &quot;Got to working directory&quot; option. The &quot;Files&quot; pane updates and shows the contents of directory &quot;\/projectnb\/scv\/milechin\/r_code\/&quot;.\" width=\"800\" class=\"alignnone size-full wp-image-153750\" style=\"border: 1px solid;\" \/><\/li>\n<li>Click on the &#8220;Packages&#8221; tab to see a list of R packages already installed and ready for your use. You can install your own R Packages if you need one that is not listed in the &#8220;Packages&#8221; tab.<br \/>\n<img src=\"\/tech\/files\/2024\/08\/Check_packages.gif\" alt=\"An animated GIF showing RStudio Server window. A mouse moves to the &quot;packages&quot; tab and clicks on it. The window shows a list of R packages already installed and ready for use in R.\" width=\"500\" class=\"wp-image-153704 size-full alignnone\" style=\"border: 1px solid;\" \/><\/li>\n<\/ol>\n<h3><a id=\"TERMINAL\" name=\"TERMINAL\"><\/a>Starting R Console within a Terminal<\/h3>\n<ol>\n<li>Open a terminal connected to the SCC.<\/li>\n<li>Print the available versions of R by executing the following command:\n<pre><code class=\"code-block\" style=\"padding: 0em 1em 0em 1em;\"><span class=\"prompt\">scc1$<\/span> <span class=\"command\">module spider R<\/span><\/code><\/pre>\n<\/li>\n<li>Use the <b>module load<\/b> command to load the version of R desired and then run the <b>R<\/b> executable to start the R console within the terminal.\n<pre><code class=\"code-block\" style=\"padding: 0em 1em 0em 1em;\"><span class=\"prompt\">scc1$<\/span> <span class=\"command\">module load R\/4.4.0<\/span>\r\n<span class=\"prompt\">scc1$<\/span> <span class=\"command\">R<\/span><\/code><\/pre>\n<\/li>\n<li>To list all the R Packages already installed, run the following <b>installed.packages()<\/b> command:\n<pre><code class=\"code-block\" style=\"padding: 0em 1em 0em 1em;\"><span class=\"prompt\">&gt;<\/span> <span class=\"command\">installed.packages()[,c(\"Package\", \"Version\")]<\/span><\/code><\/pre>\n<\/li>\n<li>To exit the R console, execute the quit function:\n<pre><code class=\"code-block\" style=\"padding: 0em 1em 0em 1em;\"><span class=\"prompt\">&gt;<\/span> <span class=\"command\">q()<\/span><\/code><\/pre>\n<\/li>\n<\/ol>\n<div class=\"highlight-yellow\"><b>NOTE:<\/b> Log-in nodes (SCC1, SCC2, GEO, and SCC4) are not to be used for computation tasks, but for general purpose tasks. This may include editing files, managing files on the file server, installing R packages, or submitting jobs. Request an <a href=\"#ONDEMAND\">OnDemand Session<\/a> if you plan to run computation tasks interactively.<\/div>\n<h2>Installing R Packages<\/h2>\n<p>Researchers are able to install their own R packages on the SCC. By default, these packages will be installed in the Home directory (~\/R\/x86_64-pc-linux-gnu-library\/4.X). When installing a package for the first time, you maybe prompted with questions about creating this directory in your Home directory. The first question will ask if you want to use a &#8220;personal library&#8221;, as an example shows below.<\/p>\n<pre><code class=\"code-block\" style=\"padding: 0em 1em 0em 1em;\"><span class=\"prompt\">&gt;<\/span> <span class=\"command\">install.packages(\"tidycensus\") <\/span>\r\n<span class=\"console\">Installing package into \u2018\/usr1\/project\/username\/R\/x86_64-pc-linux-gnu-library\/4.4\u2019 (as \u2018lib\u2019 is unspecified) \r\nWarning in install.packages : 'lib = \"\/usr1\/project\/username\/R\/x86_64-pc-linux-gnu-library\/4.4\"' is not writable \r\nWould you like to use a personal library instead? (yes\/No\/cancel)<\/span><\/code><\/pre>\n<p>Type in <b>yes<\/b> and hit <b>Enter<\/b> key.<\/p>\n<p>The second question will ask you to confirm the location of the personal library and propose a default location in your home directory:<\/p>\n<pre><code class=\"code-block\" style=\"padding: 0em 1em 0em 1em;\">\r\n<span class=\"console\">Would you like to create a personal library\r\n\u2018\/usr1\/scv\/milechin\/R\/x86_64-pc-linux-gnu-library\/4.4\u2019\r\nto install packages into? (yes\/No\/cancel) <\/span><\/code><\/pre>\n<p>Type in <b>yes<\/b>\u00a0and hit <b>Enter<\/b> key to accept the default location.<\/p>\n<p>After the directory is created, the installation should proceed as normal. If you have an issue installing an R package, please fill out the <a href=\"https:\/\/www.bu.edu\/tech\/support\/research\/software-and-programming\/software-and-applications\/request-software\/\">Software Request Form<\/a> to get assistance from our team.<\/p>\n<h2>Additional Help\/Documentation<\/h2>\n<h3>Internal Resources<\/h3>\n<ul>\n<li><a href=\"https:\/\/www.bu.edu\/tech\/support\/research\/training-consulting\/rcs-tutorial-videos-and-third-party-tutorials\/using-r\/\" target=\"_blank\" rel=\"noopener noreferrer\">Introduction to Using R and RStudio on the SCC<\/a>&#8211; a 20 minute introduction video<\/li>\n<li><a href=\"https:\/\/www.bu.edu\/tech\/support\/research\/training-consulting\/rcs-tutorial-videos-and-third-party-tutorials\/\" target=\"_blank\" rel=\"noopener noreferrer\">Recorded Tutorials<\/a> &#8211; See &#8220;Data Analysis Tutorial&#8221; section.<\/li>\n<li><a href=\"https:\/\/www.bu.edu\/tech\/support\/research\/software-and-programming\/rcs-software-packages\/r-basics\/r-faq\/\" target=\"_blank\" rel=\"noopener noreferrer\">R Frequently Asked Questions<\/a><\/li>\n<li><a href=\"http:\/\/scv.bu.edu\/examples\/r\/examples\/\" target=\"_blank\" rel=\"noopener noreferrer\">R example scripts<\/a><\/li>\n<li><a href=\"http:\/\/scv.bu.edu\/examples\/r\/tutorials\/\" target=\"_blank\" rel=\"noopener noreferrer\">Parallelization and optimization techniques and tutorial scripts<\/a><\/li>\n<li><a href=\"https:\/\/www.bu.edu\/tech\/about\/training\/classroom\/rcs-tutorials\/\" target=\"_blank\" rel=\"noopener noreferrer\"> Upcoming Workshops <\/a> &#8211; see &#8220;Data Analysis Tutorials&#8221; section.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Description R is a language and environment for statistical computing and graphics. R provides a wide variety of statistical and graphical techniques and is highly extensible. Example analysis that can be done with R include linear and nonlinear modeling, classical statistical tests, time-series analysis, classification, and clustering. Availability R is free software under the GNU&#8230;<\/p>\n","protected":false},"author":1692,"featured_media":0,"parent":76567,"menu_order":7,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages\/51114"}],"collection":[{"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/users\/1692"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/comments?post=51114"}],"version-history":[{"count":48,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages\/51114\/revisions"}],"predecessor-version":[{"id":153756,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages\/51114\/revisions\/153756"}],"up":[{"embeddable":true,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages\/76567"}],"wp:attachment":[{"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/media?parent=51114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}