Suppose I need to run a system executable (myexecutable
) file within R. I want to print a message "Please install myexecutable to run this proprogram" if it is not installed. How do I do it in R?
Asked
Active
Viewed 91 times
4

MAPK
- 5,635
- 4
- 37
- 88
-
2Possible duplicate: https://stackoverflow.com/questions/14964457/check-if-a-program-is-installed – MrFlick Feb 21 '18 at 19:46
-
Only that the duplicate does not (sufficiently) feature `Sys.which()` which is _the_ command for it. – Dirk Eddelbuettel Feb 21 '18 at 19:49
1 Answers
6
Use Sys.which()
.
Worked example
R> testForMyProg <- function(prg) { if (Sys.which(prg) == "") message("Please install ", prg) }
R> testForMyProg("lalalalaNope")
Please install lalalalaNope
R> testForMyProg("gcc")
R>
R>

Dirk Eddelbuettel
- 360,940
- 56
- 644
- 725