---
title: Getting Started
author: David Kane
tutorial:
  id: getting-started
output:
  learnr::tutorial:
    progressive: yes
    allow_skip: yes
runtime: shiny_prerendered
description: Tutorial for introducing students to tutorials when using Visual Studio Code via GitHub Codespaces.
---

```{r setup, include = FALSE}
library(learnr)
library(tutorial.helpers)
library(knitr)

knitr::opts_chunk$set(echo = FALSE)
knitr::opts_chunk$set(out.width = '90%')
options(tutorial.exercise.timelimit = 60,
        tutorial.storage = "local")
```

<!-- Get rid of the images which use dark mode. They are unreadable! -->

## Introduction
###

This tutorial, intended for beginners, teaches students how to use [VS Code](https://code.visualstudio.com/) within [GitHub Codespaces](https://github.com/features/codespaces) to run R tutorials created with the [**learnr**](https://rstudio.github.io/learnr/) package. We also introduce students to the use of the bash Terminal, the R Terminal, and [GitHub Copilot](https://github.com/copilot), an AI coding assistant.

Most students begin this tutorial after completing the setup steps outlined [here](https://ppbds.github.io/primer/getting-started.html). If you have not done that yet, do so now.

###

After starting the tutorial, your Codespace looks something like this:

```{r}
include_graphics("images/gs-1.png")
```

###

Complete the tutorial in your Codespace. At the end, you will press a button to download a copy of your answers to the `Downloads` folder on your computer. Downloading only saves the file on your computer. If your instructor wants a copy, they will tell you how to send it to them.

###

Most tutorials begin by asking for your name and email. Your instructor might also ask you to fill in the "ID" field so that your work can be matched to a grading database. If not, leave the "ID" field blank. Click "Continue," then enter your name and email. Click the **"Submit Answer"** button each time. If you make a mistake, click **"Try Again"** and submit a new answer.

If you are completing this tutorial as part of a class, use the same email address for every tutorial.

```{r info-section, child = system.file("child_documents/info_section.Rmd", package = "tutorial.helpers")}
```

## Bash Terminal
###

Each tutorial includes exercises for you to complete. Most exercises ask you to run a command in a Terminal and then copy the result into the answer box. After writing your answer, click the "Submit Answer" button, as you did above for your name and email address.

###

The **bash** Terminal is a text-based interface in which you type commands to tell your Codespace what to do. The pattern is always the same: you send a command, the Terminal executes it, and it gives you something back. In this section you will practice the most common bash commands. (In the next section you will see that the R Terminal works exactly the same way.)

###

To do the exercises, you need a bash Terminal in which to type commands. Press the plus button (`+`) on the right side of the Panel to open one.


```{r}
include_graphics("images/gs-2.png")
```

### Exercise 1

In the bash Terminal, type `whoami` and then press `return` (on Mac) or `enter` (on Windows). To "run" a command means to type it and then press this key. To avoid repeating both terms in every question, we use `Enter` to mean either the `return` or `enter` key, as appropriate.

###

The other Mac/Windows issue to be aware of is the Command key (Mac) versus Control key (Windows). 

Many shortcut key commands use the Command key --- abbreviated to `Cmd` --- or the Control key --- abbreviated to `Ctrl` --- to perform various actions, depending on the operating system you are using. We will use `Cmd/Ctrl` to mean either key, as appropriate.

###

**Do not just type the command into the answer box!** You must run the command in the bash Terminal and then copy the result.

**C**opy and **P**aste both the **C**ommand *and* the **R**esponse from the Terminal into the box below. We will abbreviate this instruction in the future as **CP**/**CR**.

```{r bash-terminal-1}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 3)
```

###

We typically provide example answers, like the one below, after you submit your own response. Do not be concerned if your answer differs from the example we show.

````
codespace-starter $ whoami
rstudio
codespace-starter $
````

###

`whoami` prints the username of the account you are signed in as. Your Codespace is a complete computer running in the cloud, and you interact with it as the `rstudio` user. It is OK if your formatting differs from ours. What matters is that you show that you executed the command as instructed.

### Exercise 2

In the bash Terminal, run `echo $0`. (Again, "run" means to type the command and then press `Enter`.)

CP/CR.

```{r bash-terminal-2}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 3)
```

###

````
codespace-starter $ echo $0
/bin/bash
codespace-starter $
````

###

A "shell" is the program that reads and interprets the commands you type in the Terminal. `echo $0` prints the name of the shell you are using: `/bin/bash`, the [Bash shell](https://en.wikipedia.org/wiki/Bash_(Unix_shell)). Every command you run in this Terminal --- starting with the `whoami` you just ran --- is interpreted by bash.

### Exercise 3

In the bash Terminal, run `pwd`.

CP/CR.

```{r bash-terminal-3}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 3)
```

###

````
codespace-starter $ pwd
/workspaces/codespace-starter
codespace-starter $
````

###

`pwd` stands for **p**rint **w**orking **d**irectory --- the folder the Terminal is currently "in." GitHub Codespaces place your repository under `/workspaces/`, so that is where you begin. Almost every command you run acts on this directory unless you tell it otherwise.

### Exercise 4

In the bash Terminal, run `ls`.

CP/CR.

```{r bash-terminal-4}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 3)
```

###

````
codespace-starter $ ls
codespace-starter $
````

###

`ls` **l**i**s**ts the files in the working directory. Notice that nothing was printed! That is because, by default, `ls` hides any file or folder whose name begins with a dot (`.`). The directory is not actually empty, as we will see next.

### Exercise 5

In the bash Terminal, run `ls -a`.

CP/CR.

```{r bash-terminal-5}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 3)
```

###

````
codespace-starter $ ls -a
.  ..  .devcontainer  .git
codespace-starter $
````

###

The `-a` flag (for "all") tells `ls` to reveal the hidden entries. `.` is the current directory and `..` is the directory just above it. `.git` stores the project's version history, and `.devcontainer` holds the configuration for your Codespace. A "flag" like `-a` is an option that changes how a command behaves.

### Exercise 6

In the bash Terminal, run `ls .devcontainer`.

CP/CR.

```{r bash-terminal-6}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 3)
```

###

````
codespace-starter $ ls .devcontainer
AGENTS.md  STUDENT_WORKFLOW.md  connect-repo.sh  devcontainer.json  welcome.sh
codespace-starter $
````

###

Giving `ls` a directory name lists what is inside that directory. The `.devcontainer` folder tells GitHub Codespaces how to build your workshop --- which version of R, Python, and Quarto to install, and which AI tools to include --- so that every student gets an identical setup.

### Exercise 7

In the bash Terminal, run `head .devcontainer/STUDENT_WORKFLOW.md`.

CP/CR.

```{r bash-terminal-7}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 12)
```

###

````
codespace-starter $ head .devcontainer/STUDENT_WORKFLOW.md
# Student workflow

This Codespace is your **workshop** — it already has R, Python (with the
usual data-science libraries), Quarto, the AI assistants, and all the right
settings. But this `codespace-starter` repo isn't *yours*, so you won't save
your work here. Instead, you'll make your **own repo** and work in it. The
tools travel with the Codespace, so your repo needs no setup of its own.

## 1. Create or connect to your repo (one command)

codespace-starter $
````

###

`head` prints the first ten lines of a file, a quick way to peek at its contents without opening it. `STUDENT_WORKFLOW.md` explains the most important habit for this course: because `codespace-starter` is not your own repo, you create your own with `.devcontainer/connect-repo.sh` and do your work there.

### Exercise 8

Let us make the Terminal "sleep" by running `sleep 5` in the bash Terminal. The `sleep 5` command pauses execution for 5 seconds.

CP/CR.

```{r bash-terminal-8}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 3)
```

###

````
codespace-starter $ sleep 5
codespace-starter $
````

###

Many commands do their work silently and print nothing --- success is simply the return of the prompt. We can change the duration with `sleep [number]`, where the number is how many seconds the Terminal pauses.

### Exercise 9

Run `sleep 60` in the bash Terminal. This command makes the Terminal sleep for 60 seconds. To cancel the running `sleep` command, press `Ctrl + C` on your keyboard. Do so now, before `sleep 60` finishes.

CP/CR.

```{r bash-terminal-9}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 3)
```

###

````
codespace-starter $ sleep 60
^C
codespace-starter $
````

###

`Ctrl + C` interrupts whatever process is currently running in the Terminal and returns you to the prompt; the `^C` marks where you pressed it. This is one of the most useful things to know: when a command hangs or you change your mind, `Ctrl + C` stops it. You will use it again in the next exercise to stop the tutorial itself.

### Exercise 10

Read all of the following instructions before continuing. The purpose of this exercise is to demonstrate that your tutorial answers are saved automatically.

* Return to your Codespace and click the Terminal tab titled "R Tutorial" in the Panel.

```{r}
include_graphics("images/gs-3.png")
```

* Stop the tutorial by pressing `Ctrl + C` in the terminal. This is useful because it can interrupt any terminal process. A new line should appear where you can enter another command.

* To restart the tutorial, press the triangle button next to the "Getting Start" tutorial via the R Tutorials VS Code extension.

* Finally, open the tutorial.

Now that you have read all the instructions, go ahead and follow them.

###

Notice that all of your answers to previous questions have been saved. It is not a problem to quit a tutorial. In fact, if you leave a tutorial idle, it will eventually quit automatically.

## R Terminal
###

All the terminology associated with VS Code is confusing. The "Panel" is the bottom of the VS Code window. The are several "views" associated with the Panel, including "Output," "Ports," and "Terminal." Within the Terminal view, you can have multiple "terminals" running. Each terminal has an associated "tab" on the right side of the panel which you can use to select that terminal. Different terminals serve different purposes.
###

So far, we have learn about the "bash Terminal,"" which lets you talk to the computer. The "R Terminal" lets you talk to R, the programming language you will use for data science. The two work the same way: you type a command, press `Enter`, and the Terminal executes the command and gives you something back. The only real difference is the language --- bash commands like `ls` and `pwd` on the one hand, R commands like `sqrt(16)` on the other. Each exercise in this section asks you to run a one-line command and then CP/CR.

Create a new R Terminal by pressing the down arrow next to the plus button on the right side of the Panel Toolbar and selecting "New R Terminal."


```{r}
include_graphics("images/gs-4.png")
```

###

You may need to click on the new  "R Interactive" tab at the bottom of the list of terminals in order to bring it to the top of the Panel.

### Exercise 1

In the R Terminal, run `4 + 5`.

CP/CR.

```{r r-terminal-1}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 3)
```

###

````
R 4.5.3> 4 + 5
[1] 9
R 4.5.3>
````

###

At its simplest, R is a calculator. Just as the bash Terminal took `whoami` and handed back your username, the R Terminal takes `4 + 5` and hands back the result. You send a command; the Terminal sends something back. The `[1]` at the start of the output is a counter telling you that the line begins with the first element of the result --- useful when a result has many values spread across several lines.

### Exercise 2

In the R Terminal, run `sqrt(16)`.

CP/CR.

```{r r-terminal-2}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 3)
```

###

````
R 4.5.3> sqrt(16)
[1] 4
R 4.5.3>
````

###

`sqrt()` is a **function**. You "call" a function by writing its name followed by parentheses, placing any input --- here, `16` --- inside them. That input is called an **argument**. Almost everything you do in R involves calling functions on arguments.

### Exercise 3

In the R Terminal, run `getwd()`. This stands for **get** **w**orking **d**irectory, meaning that we want to know the directory in which the R process is currently located.

CP/CR.

```{r r-terminal-3}
question_text(NULL,
    answer(NULL, correct = TRUE),
    allow_retry = TRUE,
    try_again_button = "Edit Answer",
    incorrect = NULL,
    rows = 3)
```

###

````
R 4.5.3> getwd()
[1] "/workspaces/codespace-starter"
R 4.5.3>
````

###

`getwd()` is the R equivalent of the bash command `pwd` you ran earlier. Here it shows that R is operating inside your Codespace at `/workspaces/codespace-starter`. Note that `getwd()` takes no arguments, but you still need the parentheses to call it.

### Exercise 4

In the R Terminal, run `R.version.string`.

CP/CR.

```{r r-terminal-4}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 3)
```

###

````
R 4.5.3> R.version.string
[1] "R version 4.5.3 (2026-03-11)"
R 4.5.3>
````

###

Your version of R may differ from the example above --- that's fine, as long as it's reasonably recent. `R.version.string` is not a function call --- it has no parentheses --- but a built-in variable whose value R simply prints.

### Exercise 5

`show_file()` is a commonly used function from the **tutorial.helpers** package. It makes it easy for you to share the contents of another file with your instructor, especially a file that you have edited.

You can generally call a function by giving its name followed by parentheses, as with `getwd()`. However, it can be safer to prefix the function name with the name of the package in which the function is found, separated by two colons. Since `show_file()` is in the **tutorial.helpers** package, we can call it using this "double-colon" notation: `tutorial.helpers::show_file()`.

In the R Terminal, run this command:

```
tutorial.helpers::show_file(file.path(R.home(), "COPYING"), end = 7)
```

CP/CR.

```{r r-terminal-5}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 10)
```

###

```{r r-terminal-5-test, include = FALSE}
tutorial.helpers::show_file(file.path(R.home(), "COPYING"), end = 7)
```

For now, don't worry about what `R.home()` and `file.path()` are doing, although you can read about them by running `?R.home` and `?file.path` in the R Terminal. Those details are less important than seeing the intended usage of `show_file()`.

### Exercise 6

Tutorials can include written responses. You have already seen several examples. Sometimes those written answers are simply copies of commands and their results. Other times, we will ask you to write one or more sentences of prose.

Copy and paste everything from the exercise header above, beginning with "Exercise 6," through the end of this sentence into the answer box below. In other words, you are copying from this tutorial, not from the Terminal. Press "Submit Answer."

```{r r-terminal-6}
question_text(NULL,
    message = "We will sometimes provide an answer to written questions, as we do here. Other times, we won't. In the former case, we will not allow you to resubmit your answer. Don't stress! Most instructors grade tutorials on pass/fail basis, so, as long as you make an honest effort, you will do fine.",
    answer(NULL,
           correct = TRUE),
    allow_retry = FALSE,
    incorrect = NULL,
    rows = 6)
```

### Exercise 7

We frequently ask you to `copy` content from an HTML file such as a webpage. Do not worry if what you copy appears messy or loses its formatting; that is perfectly fine. Our main concern is that what you paste contains roughly the information it is supposed to contain.

###

Go to [the homepage](https://ppbds.github.io/tutorial.helpers/) of the **tutorial.helpers** package and copy everything in the browser window from "tutorial.helpers" in the upper-left corner through the end of the `About this package` section.

CP/CR.

```{r r-terminal-7}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 3)
```

###

````
tutorial.helpers
0.6.2.9008
Reference
Articles
Changelog
Search for
Tutorial Helper Functions
About this package
tutorial.helpers provides functions to help you write R tutorials, especially if you follow my advice about the best way to do so.
````

Again, your answer never needs to match ours exactly.

## GitHub Copilot
###

Your Codespace includes **GitHub Copilot**, an AI coding assistant that can answer questions, explain code, create and edit files, and run commands for you. 

Copilot Chat usually opens automatically when your Codespace starts. If it is not open, click the menu button in the top-left corner, marked with a red circle below. Select **View**, and then click **Chat**, marked with a red rectangle. You can also open Chat by pressing `Cmd/Ctrl + Alt + I`.

```{r}
include_graphics("images/cs-open-copilot-chat.png")
```

When the Copilot Chat view opens, select **Agent** from the mode menu near the chat box. Agent mode lets Copilot work with files and Terminals in your Codespace. If you are asked to sign in or authorize GitHub Copilot, follow the instructions on the screen. Keep the Chat view open throughout this section.

### Exercise 1

The bottom of the Chat window looks like this:

```{r}
include_graphics("images/gs-5.png")
```

In the Copilot chat box, type the following message and press `Enter`. Replace `<your-name>` with your actual name.

```
Hello! My name is <your-name>
```

Copy Copilot's response into the box below. This is the only exercise in which we ask you to copy what the AI says back. Usually, we will confirm its work by checking the file which it has edited.

```{r ai-assistant-1}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 3)
```

###

```
Hello David! How can I help you today?
```

###

GitHub Copilot works like ChatGPT. You "talk" to it in plain English, and it responds. Your exact response will differ from ours --- AI does not give usually the same answer twice --- and that is fine.

### Exercise 2

Copilot can do much more than chat. In Agent mode, which is the default, it can create and edit files for you. Send this message:

```
Make a file called presidents.txt which includes the names of the first 5 US Presidents.
```

Copilot will create the file in your working directory. Copilot may open the new file in the Editor and display a **Keep** button. Click **Keep** to accept the file.

```{r}
include_graphics("images/cs-copilot-keep-editor.png")
```

The **Keep** button may also appear in a smaller change summary near the Copilot chat box.

```{r, out.width = '45%'}
include_graphics("images/cs-copilot-keep-summary.png")
```

From the R Terminal, run:

```
tutorial.helpers::show_file("presidents.txt")
```

CP/CR.

```{r ai-assistant-2}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 8)
```

###

````
George Washington
John Adams
Thomas Jefferson
James Madison
James Monroe
````

###

You can also see the new file without using the Terminal. Click the Explorer icon at the top of the Activity Bar. The Explorer lists every file in your working directory, and `presidents.txt` should now appear there. Click on it to open the file in the Editor and see its contents directly. The Explorer is useful whenever you want to inspect a file that AI created or edited.

The Explorer icon is marked with a red square below.

```{r}
include_graphics("images/gs-6.png")
```

### Exercise 3

We are done with the presidents example. Now ask Copilot to create a very small R program. Send this message:

```
Create an R script called script.R containing only this line: 2 + 2. Do not run the script.
```

If Copilot asks you to keep or accept the file, do so. Then run this command in the R Terminal:

```
tutorial.helpers::show_file("script.R")
```

CP/CR.

```{r ai-assistant-3}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 5)
```

###

````
2 + 2
````

###

An R script is a plain-text file whose name ends in `.R`. Creating or opening a script does not run it. Running the script means asking R to execute the instructions saved inside it.

### Exercise 4

In the Explorer, click `script.R` to open it in the Editor. Click the triangular **Run Source** button in the upper-right corner of the Editor. Look in the R Terminal for the generated `source()` command, the line of code, and its result.

The Run Source button is marked with a red square below.

<!-- DK: Replace this nonsense. -->

<div style="position: relative; width: 90%; margin: 1em auto;">
  <img src="images/cs-run-source.png" alt="VS Code Editor with script.R open" style="display: block; width: 100%; height: auto;">
  <div aria-hidden="true" style="position: absolute; left: 93.1%; top: 0.5%; width: 1.9%; height: 4.5%; border: 4px solid red; box-sizing: border-box;"></div>
</div>

CP/CR.

```{r ai-assistant-4}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 10)
```

###

````
R 4.5.3> source("/workspaces/codespace-starter/script.R", encoding = "UTF-8", echo = TRUE)

> 2 + 2
[1] 4
R 4.5.3>
````

###

The Run Source button saves the open file and sends a `source()` command with its full path to the active R Terminal. The setting `echo = TRUE` results in each instruction being displayed before R executes it.

### Exercise 5

Make sure `script.R` is still open. Place your cursor on the line `2 + 2` and press `Cmd/Ctrl + Enter`. This runs the current line rather than sourcing the entire file.

CP/CR.

```{r ai-assistant-5}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 7)
```

###

````
R 4.5.3> 2 + 2
[1] 4
R 4.5.3>
````

###

The Editor must have focus so VS Code knows which line to send to the active R Terminal.

### Exercise 6

Keep your cursor in the `script.R` Editor and press `Cmd/Ctrl + Shift + Enter`. This sources the entire file with echo, just like the Run Source button. CP/CR.

```{r ai-assistant-6}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 10)
```

###

````
R 4.5.3> source("/workspaces/codespace-starter/script.R", encoding = "UTF-8", echo = TRUE)

> 2 + 2
[1] 4
R 4.5.3>
````

###

The button and the keyboard shortcut both source the saved file in your current R session. Running the current line also uses that session, but it sends only the line where your cursor is located.

### Exercise 7

Now run the script outside your open R session. Press the plus button (`+`) on the right side of the Panel to open a new bash Terminal. At the bash prompt, run:

```
Rscript script.R
```

CP/CR.

```{r ai-assistant-7}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 8)
```

###

````
codespace-starter $ Rscript script.R
[1] 4
codespace-starter $
````

###

`Rscript` starts a new R process, runs the file, and closes that process when the script finishes. It does not use the R session that is already open in your other Terminal.

### Exercise 8

AI can also run files for you. Return to Copilot Chat and tell your AI:

```
Run script.R
```

Copilot will usually choose a command such as `Rscript script.R`. If it asks for permission, provide it. Copilot should report the result in the Chat view. Enter that result in the box below.

```{r ai-assistant-8}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 2)
```

###

`4`

###

You have now run the same script five ways: with the Run Source button, with two keyboard shortcuts, by typing `Rscript` in a bash Terminal, and by asking Copilot to run the script. Asking Copilot delegates the work, but Copilot still uses commands on the computer to carry it out.

### Exercise 9

So far, `script.R` calculates `2 + 2` and displays the result, but it does not give that result a name. In R, an **object** is a name used to store a value so you can use it again. The instruction `x <- 2 + 2` creates an object named `x` and stores the value `4` in it. An object exists only in the R session where it was created.

Then ask Copilot to edit and run the script:

```
Edit script.R so its only line is x <- 2 + 2. Then run it with Rscript.
```

If Copilot asks for permission, inspect and approve the command. When it finishes, return to the same R Terminal and run:

```
exists("x")
```

CP/CR.

```{r ai-assistant-9}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 4)
```

###

````
R 4.5.3> exists("x")
[1] FALSE
R 4.5.3>
````

###

Copilot used `Rscript`, which created `x` in a separate R process and then closed that process. Your open R session therefore still reports `FALSE`: it does not know about the `x` that briefly existed in the other session.

### Exercise 10

Open `script.R` in the Editor. It should now contain `x <- 2 + 2`. Keep your cursor in the Editor and press `Cmd/Ctrl + Shift + Enter` to source the file in your open R session. Then run this command in the R Terminal:

```
x
```

CP/CR.

```{r ai-assistant-10}
question_text(NULL,
	answer(NULL, correct = TRUE),
	allow_retry = TRUE,
	try_again_button = "Edit Answer",
	incorrect = NULL,
	rows = 10)
```

###

````
R 4.5.3> source("/workspaces/codespace-starter/script.R", encoding = "UTF-8", echo = TRUE)

> x <- 2 + 2
R 4.5.3> x
[1] 4
R 4.5.3>
````

###

This time, `x` exists because the Editor sourced `script.R` in your open R session. The five ways to run the script do not all use the same R session:

| Method | R session used |
|---|---|
| Run Source button | Your open R Terminal |
| `Cmd/Ctrl + Enter` | Your open R Terminal; current line only |
| `Cmd/Ctrl + Shift + Enter` | Your open R Terminal; entire file |
| `Rscript script.R` in bash | A new process that closes afterward |
| Ask Copilot to use `Rscript` | A new process that closes afterward |

## Your answers
###

At the end of every tutorial, you will download a copy of your answers. We will do this in the next topic, labeled "Download answers." Follow the instructions there.

Make sure to answer the question about how many **minutes** you spent on the tutorial and to click "Submit Answer."

After clicking the "Download" button, you will be prompted to save a file named `getting-started_answers.html`. By default, this file will be saved in the `Downloads` folder on your computer. This action only downloads the file; it does not send the file to anyone.

Unless your instructor tells you otherwise, you should use the default file name, which will usually be of the form `short-name-of-tutorial` + `_answers` + `.html`.

```{r your-answers-0, child = system.file("child_documents/download_answers.Rmd", package = "tutorial.helpers")}
```

## Summary
###

You now understand how tutorials work, how to use bash and R Terminals, how to ask GitHub Copilot to create and edit files, and five ways to run an R script. You also know how to download a copy of your answers. Good luck with your data science journey!

<p>
  <img src="images/neo-cs.gif" alt="Neo learns codespaces" width="320">
</p>
