|
9 | 9 | <meta name="author" content="Dan Olner"> |
10 | 10 | <meta name="dcterms.date" content="2025-05-16"> |
11 | 11 |
|
12 | | -<title>Getting started with using R and RStudio (in the cloud or on your own machine) – Dan Olner’s Data Dispatch</title> |
| 12 | +<title>Getting started with using R and RStudio (in the cloud or on your own computer) – Dan Olner’s Data Dispatch</title> |
13 | 13 | <style> |
14 | 14 | code{white-space: pre-wrap;} |
15 | 15 | span.smallcaps{font-variant: small-caps;} |
|
158 | 158 | <header id="title-block-header" class="quarto-title-block default page-columns page-full"> |
159 | 159 | <div class="quarto-title-banner page-columns page-full"> |
160 | 160 | <div class="quarto-title column-body"> |
161 | | - <h1 class="title">Getting started with using R and RStudio (in the cloud or on your own machine)</h1> |
| 161 | + <h1 class="title">Getting started with using R and RStudio (in the cloud or on your own computer)</h1> |
162 | 162 | <div class="quarto-categories"> |
163 | 163 | <div class="quarto-category">training</div> |
164 | 164 | <div class="quarto-category">code</div> |
@@ -200,30 +200,31 @@ <h1 class="title">Getting started with using R and RStudio (in the cloud or on y |
200 | 200 |
|
201 | 201 | <section id="using-r-and-rstudio-1-on-your-own-computer-or-2-posit.cloud-in-the-browser" class="level2"> |
202 | 202 | <h2 class="anchored" data-anchor-id="using-r-and-rstudio-1-on-your-own-computer-or-2-posit.cloud-in-the-browser">Using R and RStudio: (1) on your own computer or (2) posit.cloud in the browser</h2> |
203 | | -<p>I’m running an “R + regional economic data” taster session in June. It won’t be necessary to use R during the session to follow along - <strong>but if you want to have a go at running the code I’ll be talking through and don’t yet have R/RStudio, here’s how to get quickly set up</strong>, either online or on your own computer<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a>.</p> |
| 203 | +<p>I’m running an “R + regional economic data” taster session in June. It won’t be necessary to use R during the session to follow along - <strong>but if you want to have a go at running the code I’ll be talking through and don’t yet have R/RStudio, here’s how to get quickly set up</strong>, either online through a browser, or with R and RStudio installed on your own computer<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a>.</p> |
204 | 204 | <p>To do this, you’ll need to do <strong>one</strong> of the following:</p> |
205 | 205 | <ol type="1"> |
206 | 206 | <li><p><strong>Use RStudio in your browser with a <a href="https://posit.cloud">posit.cloud account</a></strong>. The <strong>free version</strong> is limited (very small memory, for instance) but <strong>it’s a very quick and easy option to have a play with R</strong> and will be fine for the taster session. <strong>The next section below talks through setting up in posit.cloud.</strong></p></li> |
207 | | -<li><p><strong>Use R and RStudio on your own computer</strong>. If you have a machine where you’re able to install your own software <a href="https://cran.rstudio.com/">then go here</a> to download/install the right version of R for your operating system, and <a href="https://posit.co/download/rstudio-desktop/">here to download/install RStudio</a> (again, pick the correct one for your OS). (Though see bullet point 2 below if using a work machine.)</p></li> |
| 207 | +<li><p><strong>Install R and RStudio on your own computer</strong>. If you have a machine where you’re able to install your own software <a href="https://cran.rstudio.com/">then go here</a> to download/install the right version of R for your operating system, and <a href="https://posit.co/download/rstudio-desktop/">here to download/install RStudio</a> (again, pick the correct one for your OS). (Though see bullet point 2 below if using a work machine.)</p></li> |
208 | 208 | </ol> |
209 | 209 | <ul> |
210 | 210 | <li>The next chunk will talk through <strong>setting up a posit.cloud project.</strong></li> |
211 | 211 | <li>The chunk after that talks through getting started with an RStudio project, and will <strong>be nearly the same</strong> whether you’re using RStudio online or on your machine (with just one tweak, explained in the breakout box).</li> |
212 | 212 | </ul> |
213 | 213 | <p>Any questions/issues, let me know at d dot older at sheffield dot ac dot uk or <a href="https://www.linkedin.com/in/danolner/">message me on LinkedIn</a> and I’ll try to answer.</p> |
214 | 214 | </section> |
215 | | -<section id="if-using-rstudio-online-set-up-posit.cloud-account-and-create-your-rstudio-project" class="level2"> |
216 | | -<h2 class="anchored" data-anchor-id="if-using-rstudio-online-set-up-posit.cloud-account-and-create-your-rstudio-project">If using RStudio online: set up posit.cloud account and create your RStudio project</h2> |
| 215 | +<section id="if-using-rstudio-online-set-up-a-posit.cloud-account-and-create-your-rstudio-project" class="level2"> |
| 216 | +<h2 class="anchored" data-anchor-id="if-using-rstudio-online-set-up-a-posit.cloud-account-and-create-your-rstudio-project">If using RStudio online: set up a posit.cloud account and create your RStudio project</h2> |
217 | 217 | <p>Here’s the steps to get up and running through a browser using posit.cloud.</p> |
218 | 218 | <ul> |
219 | 219 | <li><a href="https://login.posit.cloud/login">Create an account at posit.cloud</a> using the ‘sign up’ box, and then log in. That’ll take you to your online workspace.</li> |
220 | 220 | <li>Click the <strong>new project</strong> button, top right</li> |
221 | | -<li>Select ‘new project from template’ and then “Data Analysis in R with the tidyverse” (if not already selected). This comes pre-installed with the tidyverse package, which we’ll be using. Select then click OK down at the bottom. <strong>This will open your RStudio project where we’ll do the coding.</strong></li> |
| 221 | +<li>Select ‘<strong>new project from template</strong>’ (as in the pic below) and then “Data Analysis in R with the tidyverse” (if not already selected). This template comes pre-installed with the tidyverse package, which we’ll be using. Select then click OK down at the bottom. <strong>This will open your RStudio project where we’ll do the coding.</strong></li> |
222 | 222 | </ul> |
| 223 | +<p><img src="newproject.png" class="img-fluid"></p> |
223 | 224 | </section> |
224 | 225 | <section id="make-a-new-r-script-and-add-a-library" class="level2"> |
225 | 226 | <h2 class="anchored" data-anchor-id="make-a-new-r-script-and-add-a-library">Make a new R script and add a library</h2> |
226 | | -<p>Now you should <strong>either be in RStudio online through posit.cloud</strong> or <strong>you’ve opened RStudio on your own machine.</strong> From here…</p> |
| 227 | +<p>Now you should <strong>either be in RStudio online through posit.cloud</strong> or <strong>if using RStudio installed on your own computer, open that now</strong>. From here…</p> |
227 | 228 | <ul> |
228 | 229 | <li><strong>Create a new R script</strong> by going to ‘file > new file > new R script’ (or using the <strong>CTRL+SHIFT+N</strong> shortcut). A new script will appear, currently just called <em>‘Untitled1’</em> until it’s saved for the first time.</li> |
229 | 230 | <li><strong>At this point, it should look something like this:</strong></li> |
@@ -286,12 +287,12 @@ <h2 class="anchored" data-anchor-id="make-a-new-r-script-and-add-a-library">Make |
286 | 287 | <h2 class="anchored" data-anchor-id="running-code-in-an-r-script-loading-the-tidyverse-library">Running code in an R script / loading the tidyverse library</h2> |
287 | 288 | <p>All code will run in the console - what we do with scripts is just send our written code to the console. We do this in a couple of ways:</p> |
288 | 289 | <ol type="1"> |
289 | | -<li>In your R script, if no code text is highlighted/selected, RStudio will <strong>Run the code line by line</strong> (or chunk by chunk, but we’ll come to that).</li> |
290 | | -<li>If a block of text is highlighed, the whole block will run. So e.g. if you select-all in a script and then run it, the entire script will run.</li> |
| 290 | +<li>In your R script, if no code text is highlighted/selected, RStudio will <strong>Run the code line by line</strong> (or chunk by chunk - we’ll cover that in the taster session).</li> |
| 291 | +<li>If a block of text is highlighted, the whole block will run. So e.g. if you select-all in a script and then run it, the entire script will run.</li> |
291 | 292 | </ol> |
292 | 293 | <p>Let’s do #1: <strong>Run the code line by line</strong>.</p> |
293 | 294 | <ul> |
294 | | -<li><strong>To test this, we’ll load the tidyverse library with the code we just pasted in</strong>: put the cursor at the end of the <code>libary(tidyverse)</code> line in the script (if it’s not there already), either with the mouse or keyboard. (Keyboard navigation is mostly the same as any other text editor like Word, but <a href="https://support.posit.co/hc/en-us/articles/200711853-Keyboard-Shortcuts-in-the-RStudio-IDE">here’s a full shortcut list</a> if useful.)</li> |
| 295 | +<li><strong>To test this, we’ll load the tidyverse library with the code we just pasted in</strong> (which is just one line of code at the moment!) Put the cursor at the end of the <code>libary(tidyverse)</code> line in the script (if it’s not there already), either with the mouse or keyboard. (Keyboard navigation is mostly the same as any other text editor like Word, but <a href="https://support.posit.co/hc/en-us/articles/200711853-Keyboard-Shortcuts-in-the-RStudio-IDE">here’s a full shortcut list</a> if useful.)</li> |
295 | 296 | <li>Once there, either use the ‘run’ button, top right of the script window, or (much easier if you’re doing this repeatedly) <strong>press CTRL+ENTER to run it.</strong></li> |
296 | 297 | </ul> |
297 | 298 | <p>You should see the code get sent to the console, and a message like the one below confirming that R is ‘Attaching core tidyverse packages’. <strong>The tidyverse library is now loaded</strong>.</p> |
|
0 commit comments