From 3ac830e6ad3fca58764f86619d1c907dc433c51f Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Tue, 25 May 2021 14:43:26 +1000 Subject: [PATCH 1/2] add additional check to get perl path from Sys.getenv() --- R/utils.R | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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) From 51b12bcde516c30fbde4f902a816405cb56eb2be Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Tue, 25 May 2021 15:05:19 +1000 Subject: [PATCH 2/2] update to use find_perl function --- R/cloc-recognized-languages.r | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) 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"),