R
We will use the package swirl
to learn more about several fundamental concepts in R
.
Conservation Biology Spring 2023
Conservation Biology Spring 2023
workspace at this linkWeek 1
assignment (direct link to the Week 1
project)library(swirl)
swirl()
| Welcome to swirl!...call yourself something unique.
What shall I call you?
R
, you may see functions popping up in auto-complete.Char
.swirl
will interact with you in the console, and any time you see three blue dots (an ellipsis), you should hit enter.| Thanks, <FIRST NAME>. Let's cover a couple of quick housekeeping items...
swirl
steps, which lead to this query in red text: | Please choose a course, or type 0 to exit swirl
swirl
has mentioned the R prompt (>)
several times.>
is an example of a command prompt where you tell a computer (in this case, the server hosting RStudio Server which is running R
code) to execute your command.>>>
(if you are interacting with Python on the command line in a terminal). In Unix operating systems (e.g. Linux distributions or Mac OS), the command prompt for the terminal is often denoted by $
.>
in the R
console within RStudio Server is where R
awaits your instructions (commands).| Please choose a course...
), type 1
after the blue text reading Selection:
| Please choose a lesson...
, please type 1
after the blue text reading Selection:
.
1: Basic Building Blocks
lesson!R
using this first class in swirl
.swirl
instructions at that step. You can always use the vertical navigation bar on the right-hand side of the console to roll back up and see what the last instruction was. For example, in response to this instruction:| To see another example of how this vector 'recycling' works, try
| adding c(1, 2, 3, 4) and c(0, 10). Don't worry about saving the
| result in a new variable.
my command here was incorrectly specified (typed in at the R
command prompt >
):
c(1, 2, 3, 4) _ c(0, 10)
and threw an error:
Error: unexpected input in "c(1, 2, 3, 4) _"
In this case, I ended up fixing it by typing:
c(1, 2, 3, 4) + c(0, 10)
Unfortunately, with these types of syntax errors (akin to a grammatical error in a human language, like kluging your verb conjugation and forgetting the term for a conjunction to join two clauses together), swirl
won’t jump in and “automagically” help you.
If you get really stuck, first try entering something that is syntatically correct in the console at the command prompt. For instance, you could try myName <- "Char"
. While this isn’t the correct answer to this swirl
instruction, because this command can be interpreted by R
, you’ll get kicked back into swirl
instructions that may offer you something that you could directly copy and paste into the console, e.g.:
| That's not exactly what I'm looking for. Try again. Or, type info()
| for more options.
| Type c(1, 2, 3, 4) + c(0, 10, 100) to see how R handles adding two
| vectors, when the shorter vector's length does not divide evenly
| into the longer vector's length. Don't worry about assigning the
| result to a variable.
(Note that here you would type or copy and paste c(1, 2, 3, 4) + c(0, 10, 100)
into the console at the command prompt >
.)
>
), you can exit the course and swirl
at any time by typing bye()
into the console.
swirl
will save where you are in the course so you won’t lose your progress!|=========
, the number at the right hand side, after another |
represents the percentage of this course that you have completed.swirl
asking:| Would you like to receive credit for completing this course on
| Coursera.org?
I recommend typing in 2
(representing “No”) at the Selection:
field.
swirl
will tell you that you’ve completed the course, you will see the following in red text:| Excellent work!
| You've reached the end of this lesson...
| Please choose a course, or type 0 to exit swirl.
In response to the blue Selection:
query, please type 0.
swirl
course, please navigate to the Gradescope POM subpage in our Sakai site and select the correct option for the Completion of swirl class (Basic Building Blocks)
assignment. Please also nominate a guest speaker for our class.