Searches for an executable in a some places and use the highest version found (unless a specific version is requested).

The function mimic the behavior of the rmarkdown::find_pandoc() function in order to locate programs.

Some methods work differently depending on the OS or the program:

  • Under Windows, the search for 'Google Chrome', 'Mozilla Firefox', 'Microsoft Word', 'Microsoft PowerPoint' and 'Microsoft Excel' is done in the registry, which means that only one version can be chosen, the one referenced in the registry. (you still can force another path with argument dir).

  • 'Microsoft Word', 'Microsoft PowerPoint' and 'Microsoft Excel' can not be located on linux OS.

  • the search for 'pip' is using the result of the search of 'python' to find the corresponding 'pip' executable.

exec_locate(exec, cache = TRUE, dir = NULL, version = NULL)

Arguments

exec

executable identifier, a single character. Use one of these values:

  • chrome: 'Google Chrome' executable

  • firefox: 'Mozilla Firefox' executable

  • libreoffice: 'LibreOffice' executable

  • node: 'node.js' executable

  • npm: 'npm' executable

  • python: 'python' executable

  • pip: 'pip' executable

  • excel: 'Microsoft Excel' executable

  • word: 'Microsoft Word' executable

  • powerpoint: 'Microsoft PowerPoint' executable

cache

if FALSE, search for the executable again even if the executable has been found previously.

dir

A character vector of directory paths under which the executable may be found.

version

The version of the executable to look for (e.g., "14.15.4"). If NULL (the default), it searches for the highest version.

Value

A list containing the path of the executable and its version if found. If not found, the version will be 0 and the exec_file will be NULL.

libreoffice

On some Ubuntu platforms, 'LibreOffice' require to add in the environment variable LD_LIBRARY_PATH the following path: /usr/lib/libreoffice/program (you should see the message "libreglo.so cannot open shared object file" if it is the case). This can be done with R command Sys.setenv(LD_LIBRARY_PATH = "/usr/lib/libreoffice/program/")

See also

exec_available() will check if an executable is available and exec_version() will return the version of a located executable.

Examples

exec_locate("firefox")
#> $exec_file
#> [1] "/usr/bin/firefox"
#> 
#> $version
#> [1] ‘131.0.3’
#> 
exec_locate("chrome")
#> $exec_file
#> NULL
#> 
#> $version
#> [1] ‘0’
#> 
exec_locate("chrome", version = "88.0.4324.150")
#> $exec_file
#> NULL
#> 
#> $version
#> [1] ‘0’
#> 
exec_locate("libreoffice")
#> The following command failed: /usr/bin/soffice --version
#> with following log:
#> /usr/lib/libreoffice/program/soffice.bin: error while loading shared libraries: libreglo.so: cannot open shared object file: No such file or directory
#> $exec_file
#> NULL
#> 
#> $version
#> [1] ‘0’
#> 
exec_locate("node")
#> $exec_file
#> [1] "/usr/bin/node"
#> 
#> $version
#> [1] ‘18.8.0’
#> 
exec_locate("npm")
#> $exec_file
#> NULL
#> 
#> $version
#> [1] ‘0’
#> 
exec_locate("python")
#> $exec_file
#> [1] "/opt/python/3.12.4/bin/python3"
#> 
#> $version
#> [1] ‘3.12.4’
#> 
exec_locate("pip")
#> $exec_file
#> [1] "/opt/python/3.12.4/bin/pip3"
#> 
#> $version
#> [1] ‘24.3.1’
#> 
exec_locate("excel")
#> $exec_file
#> NULL
#> 
#> $version
#> [1] ‘0’
#> 
exec_locate("word")
#> $exec_file
#> NULL
#> 
#> $version
#> [1] ‘0’
#> 
exec_locate("powerpoint")
#> $exec_file
#> NULL
#> 
#> $version
#> [1] ‘0’
#>