diff --git a/R/cloc-recognized-languages.r b/R/cloc-recognized-languages.r index d13bc7d..baa1052 100644 --- a/R/cloc-recognized-languages.r +++ b/R/cloc-recognized-languages.r @@ -27,14 +27,7 @@ #' cloc_recognized_languages() cloc_recognized_languages <- function() { - perl <- Sys.which("perl") - - if (perl == "") { - stop( - "Cannot find 'perl'. cloc requires perl to be installed and on the PATH.", - call. = FALSE - ) - } + perl <- find_perl() c( system.file("bin/cloc.pl", package = "cloc"), diff --git a/R/utils.R b/R/utils.R index 78d99fb..58c4b43 100644 --- a/R/utils.R +++ b/R/utils.R @@ -10,10 +10,17 @@ find_perl <- function() { perl <- Sys.which("perl") if (perl == "") { - stop( - "Cannot find 'perl'. cloc requires perl to be installed and on the PATH.", - call. = FALSE - ) + + try({perl <- Sys.getenv()[['perl']]}, silent = TRUE) + + if (perl == "") { + stop( + "Cannot find 'perl'. cloc requires perl to be installed and on the PATH.\n", + " Or add an entry to .Renviron file like perl='/path/to/perl.exe'.", + call. = FALSE + ) + } + } return(perl)