This exercise explores running R interactively in two ways: issuing commands that run immediately at the R prompt, and executing a script of these commands once the script has been created and saved.

Get an interactive node with idev. Remember to include the -A option if you have more than one account.

After your idev job starts, a command prompt will appear, and you can begin your interactive development session. Job status is reported every 4 seconds: (PD=pending, R=running).


--> After your idev job begins to run, a command prompt will appear,
--> and you can begin your interactive development session.
--> We will report the job status every 4 seconds: (PD=pending, R=running).

--> job status:  PD
--> job status:  R

--> Job is now running on masternode= c205-016...OK
--> Sleeping for 7 seconds...OK
--> Checking to make sure your job has initialized an env for you....OK
--> Creating interactive terminal session (login) on master node c205-016.

ssh -Y -A -o StrictHostKeyChecking no c205-016
TACC Frontera System
Provisioned on 23-Dec-2020 at 05:48

Once you have obtained a node, if you did not do so on the login node, load the R and RstatsPackages (after loading the module dependencies) and then start R:

Now enter some data and do something with it. The following is just an example:

Interactive mode allows for data exploration and checking elements of code, with computational resources exceeding those which may be available to you locally. But in many cases, you will want to submit scripts as batch jobs.

To complete this exercise, you will have to create an R script with these same commands embedded and source it. This will execute all of the lines in the file you source and behave in a similar fashion to the way it will when you run it as a script. In particular, printing has to be done differently than when you are just typing commands at the command line. Quit R (quit() or ctrl-d), exit the interactive session to return to the login node (ctrl-d), and create a file called with the commands you entered interactively (you do not necessarily need to leave the interactive session to do this, but any time spent will count against your allocation). Substitute , and for the lines , and . Now get back into an interactive session, start R, and source the script file (using here the assumption that you saved the script file in your home directory):

Do you get the same output as when you typed in the first set of commands? You should! Do note that the R interpreter will not be able to resolve $HOME to a file path, so you should include the full path to the file. You can also omit the path entirely if the script is in your current working directory.

 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Access Statement
CVW material development is supported by NSF OAC awards 1854828, 2321040, 2323116 (UT Austin) and 2005506 (Indiana University)