I'm developing a package for a research project. It uses an external executable. I don't want to ship it inside this package but I want to check if it is installed (present in the system PATH, maybe using Sys.which) or if the user set the path to the executable with options.
I don't know what's the best to do in this case, should I check once with .onAttach, when loading the main functions. Should I store the path in options or in an environment.
Do you know any good practice for that or god examples
@JeanM I agree that using Sys.which() is the best option for checking if the executable is installed. From ?system:
There are many pitfalls in using system to ascertain if a command can be run — Sys.which is more suitable.
As an example, I explored the rmarkdown package, which relies on pandoc. It uses the environment option. Here's how the rmarkdown package solves this problem:
It creates an environment .pandoc to store the location and version of pandoc - pandoc.R#L705
Each time the user executes render() to build a document, the function pandoc_available() is called, which in turn calls find_pandoc()
find_pandoc() first checks the internal package environment. If this is the first time that render() has been run, it calls find_program("pandoc")
find_program() searches for pandoc using Sys.which(): util.R#L286
Finally, if pandoc is found, then the environment is updated so that it doesn't need to be searched for again (until the R session is restarted) - pandoc.R#L575