I’m starting to work with R. Although I’m more used to python.
I want to do a script in R that uses the library MASS. I though about doing a Try, Except to see if the library exists, otherwise install it.
Something like this:
Try:
library("MASS")
Except SomeError:
install.packages("MASS")
library("MASS")
Or perhaps in R this doesn’t make much sense.
Anyway any suggestions is welcome 🙂
The function
requireis virtually identical tolibrary, except it returns a logical value.This means you can use a simple
ifstatement, something like:R also has an error capturing mechanism. Read about it at
?tryor?tryCatch