A Very Brief Introduction to R, practical exercises

This lesson is taken from the first lecture of a “Using R” course.

Download the self paced slide show (pdf).

You will need R installed on your local computer, or if you have received your Workshop username and password, then you can login to the Workshop cloud computing environment, and use the RStudio installed there.

If you are going through these lessons in the Workshop cloud computing environment, then the files can all be found in /faculty/matt/R_Introduction. If you are running this at home, then you will need to download the files.

Each lesson consists of two files. The one named HW1.R (for example) should be opened in RStudio, and you can then go through it, and answer the embedded questions. To check your work, look in the second file HW1-KEY.R (for example).

If you have any questions, feel free to post them in this thread.

3 Likes

Hello, I am working my way through Elizabeth Prom-Wormley’s introductory videos using the workshop RStudio Cloud and I can’t load the car package using the Cloud. The error code (the part it will allow to be posted) is below, I’ve tried closing down, restarting, etc. but it hasn’t fixed it. Any ideas?

install.packages(“car”, dependencies = T)
Installing package into ‘/home/morgam34/R/x86_64-pc-linux-gnu-library/4.2’
(as ‘lib’ is unspecified)
also installing the dependencies ‘nloptr’, ‘pbkrtest’, ‘lme4’, ‘alr4’, ‘effects’

xxxx

begin installing package ‘nloptr’
make: *** [Makefile:4: nloptr.ts] Error 1
make: Target ‘all’ not remade because of errors.
/usr/lib/R/bin/Rcmd: 54: /usr/lib/R/etc/Renviron: MAKEFLAGS: not found
/usr/lib/R/bin/Rcmd: 55: /usr/lib/R/etc/Renviron: RSTUDIO_DISABLE_SECURE_DOWNLOAD_WARNING: not found

  • installing source package ‘nloptr’ …
    ** package ‘nloptr’ successfully unpacked and MD5 sums checked
    ** using staged installation
    /usr/lib/R/bin/Rcmd: 54: /usr/lib/R/etc/Renviron: MAKEFLAGS: not found
    /usr/lib/R/bin/Rcmd: 55: /usr/lib/R/etc/Renviron: RSTUDIO_DISABLE_SECURE_DOWNLOAD_WARNING: not found
    /usr/lib/R/bin/config: 54: /usr/lib/R/etc/Renviron: MAKEFLAGS: not found
    /usr/lib/R/bin/config: 55: /usr/lib/R/etc/Renviron: RSTUDIO_DISABLE_SECURE_DOWNLOAD_WARNING: not found
    /usr/lib/R/bin/Rcmd: 54: /usr/lib/R/etc/Renviron: MAKEFLAGS: not found
    /usr/lib/R/bin/Rcmd: 55: /usr/lib/R/etc/Renviron: RSTUDIO_DISABLE_SECURE_DOWNLOAD_WARNING: not found
    /usr/lib/R/bin/config: 54: /usr/lib/R/etc/Renviron: MAKEFLAGS: not found
    /usr/lib/R/bin/config: 55: /usr/lib/R/etc/Renviron: RSTUDIO_DISABLE_SECURE_DOWNLOAD_WARNING: not found
    /usr/lib/R/bin/Rcmd: 54: /usr/lib/R/etc/Renviron: MAKEFLAGS: not found
    /usr/lib/R/bin/Rcmd: 55: /usr/lib/R/etc/Renviron: RSTUDIO_DISABLE_SECURE_DOWNLOAD_WARNING: not found
    /usr/lib/R/bin/config: 54: /usr/lib/R/etc/Renviron: MAKEFLAGS: not found
    /usr/lib/R/bin/config: 55: /usr/lib/R/etc/Renviron: RSTUDIO_DISABLE_SECURE_DOWNLOAD_WARNING: not found
    /usr/lib/R/bin/Rcmd: 54: /usr/lib/R/etc/Renviron: MAKEFLAGS: not found
    /usr/lib/R/bin/Rcmd: 55: /usr/lib/R/etc/Renviron: RSTUDIO_DISABLE_SECURE_DOWNLOAD_WARNING: not found
    /usr/lib/R/bin/config: 54: /usr/lib/R/etc/Renviron: MAKEFLAGS: not found
    /usr/lib/R/bin/config: 55: /usr/lib/R/etc/Renviron: RSTUDIO_DISABLE_SECURE_DOWNLOAD_WARNING: not found
    checking whether the C++ compiler works… yes
    checking for C++ compiler default output file name… a.out
    checking for suffix of executables…
    checking whether we are cross compiling… no
    checking for suffix of object files… o
    checking whether the compiler supports GNU C++… yes
    checking whether g++ -std=gnu++14 accepts -g… yes
    checking for g++ -std=gnu++14 option to enable C++11 features… none needed
    checking how to run the C++ preprocessor… g++ -std=gnu++14 -E
    checking whether the compiler supports GNU C++… (cached) yes
    checking whether g++ -std=gnu++14 accepts -g… (cached) yes
    checking for g++ -std=gnu++14 option to enable C++11 features… (cached) none needed
    checking for pkg-config… /usr/bin/pkg-config
    checking if pkg-config knows NLopt… no
    checking for cmake… no

------------------ CMAKE NOT FOUND --------------------

CMake was not found on the PATH. Please install CMake:

  • sudo yum install cmake (Fedora/CentOS; inside a terminal)
  • sudo apt install cmake (Debian/Ubuntu; inside a terminal).
  • sudo pacman -S cmake (Arch Linux; inside a terminal).
  • sudo brew install cmake (MacOS; inside a terminal with Homebrew)
  • sudo port install cmake (MacOS; inside a terminal with MacPorts)

Alternatively install CMake from: https://cmake.org/


ERROR: configuration failed for package ‘nloptr’

  • removing ‘/home/morgam34/R/x86_64-pc-linux-gnu-library/4.2/nloptr’
    cat: lme4.out: No such file or directory
    cat: pbkrtest.out: No such file or directory
    cat: effects.out: No such file or directory
    cat: car.out: No such file or directory
    cat: alr4.out: No such file or directory
    Warning in install.packages :
    installation of one or more packages failed,
    probably ‘nloptr’, ‘lme4’, ‘pbkrtest’, ‘effects’, ‘car’, ‘alr4’

The downloaded source packages are in
‘/tmp/RtmpkLVdIu/downloaded_packages’

require(car)
Loading required package: car
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘car’

2 Likes

Thanks for letting me know. I’ve installed the car package, so you should be able continue.

When I get a chance, I’ll review the videos and see if there are any other packages I need to install, but if you run across one before I get a chance, please let me know.

Thanks for this mjmorgan!

Thanks Jeff! I was able to load library(car) as it should.
Where are the practical exercises? Are they somewhere in the /faculty/$(faculty_name)/2022 folder?

Do you mean for this tutorial, or in general?

For this tutorial they are at Index of /cdrom2022/Day0/R_Tutorial

In general, files for the practicals will be in /faculty/username where username is one of the lead faculty or one of the tutors, depending on who prepared the exercises. Then usually in a directory called 2022 or maybe BOULDER2022. It’s really up to whoever put it together.

Before the live sessions there should be a post going up in the category for that day with instructions on where to find the files. It will also usually be discussed at the start of the live session.

Sometimes the files are ready ahead of time, but often the exercise files won’t be ready until shortly before the live session.

Thanks @JML /Jeff for making it clear. I was reviewing the lesson videos and checking the folders; for some, I could identify the R scripts in the 2022/ or BOULDER2022 folders. This is why I asked this. Also, are there reading materials or PDFs that we should prepare for? The last Boulder workshop I attended were lots of readings.

/Arin

I was not given anything to make available.

I think for this year’s course the main thing to come in with is some familiarity with R and working at a command line.

Perhaps a VERY daft question(s):
(1) I assume if working with the cloud one cannot set the wkdir to your computer
(2) how the devil does one download the files onto the computer? When I click to download them, I cannot see a download button. I can jsut click on the file and it takes me to a text version within my browser. I would then have to copy and paste and save as from notepad / R and that seems an awful lot of work - what am I doing wrong?

Can you be more specific about which files you’re trying to download, and from which presentation/video/practical?

Happy to help!

No, while on the cloud the working directory will be set to someplace on the server in the cloud.

You don’t need to download the files to your local computer, just copy them into your workspace (home directory) in the cloud.

I’ll make all of your files available for download later, which is probably the easiest way to save all of the stuff you’ve worked on.