library("cowsay")
# library() # Not run here for space
install.packages("cowsay")
You actually need to:
module spider R # find the version
module load R/4.0.1-gimkl-2020a #load the version
Open R by running R
in the terminal and you should now be able to install and load the package (after choosing a CRAN session)
R
install.packages("cowsay")
library("cowsay")
If you now get back into the notebook or the console, you can access this package.
library("cowsay")
say("Moo")
Very good, but I was led to believe it would be a cow:
say("Moo",by="cow")
say("PuRRRRRRing",by="bigcat")
say("Oh hello there",by="random",by_color="pink")
say("Oh hello there",by="random",by_color="pink")
Okay, we are getting distracted here.
Be aware that a package installed for one version of R would need to be re-installed for a different R version. If you remember having installed a package but R cannot find it, you are likely to be using the wrong R version.
A job file cannot be an Rscript. You will prepare a bash job file that run an Rscript.
Using nano or the jupyter text editor we can create a basic R script making a simple plot. Let's call it testscript.R and fill it with:
png(filename="plot.png") # This line redirects plots from screen to plot.png file.
# Define the cars vector with 5 values
cars <- c(1, 3, 6, 4, 9)
# Graph the cars vector with all defaults
plot(cars)
Now let's make a bash file that can run it run_testscript.sh
#!/bin/bash -e
#SBATCH --account uoo00116 # CHANGE
#SBATCH --job-name runtestscriptR
#SBATCH --time 00:01:00
#SBATCH --mem 512MB
#SBATCH --qos debug
module load R/4.0.1-gimkl-2020a
# Help R to flush errors and show overall job progress by printing
# "executing" and "finished" statements.
echo "Executing R ..."
srun Rscript testscript.R
echo "R finished."
You can now submit that run_testscript.sh file that will run the testscript.R.
sbatch run_testscript.sh
squeue -u $USER #will show you th queue of jobs, if it is emopty, it ran or bugged
You should have a plot.png file in your directory.
In summary, I hope you'll remember the cowsay R package and maybe other things!