I've tried to create a "shortcut" that checks if a package is installed and naturally thought of going for ifelse
.
Below is a reproducible example:
ifelse(!"tree"%in%names(installed.packages()),install.packages("tree"),library(tree))
EDIT::
The package is downloaded but I still get this error presumably because the above continues to be called somehow.
Error in ans[test & ok] <- rep(yes, length.out = length(ans))[test & ok] : replacement has length zero In addition: Warning message: In rep(yes, length.out = length(ans)) : 'x' is NULL so the result will be NULL
The above appears to work except after downloading the package, an error is returned that I can't seem to figure out exactly how to solve:
I could use a different way to achieve the same but would really love to know what's going on here. Thanks!