I am attempting to run a R script from PHP. I have created a shelled out version of my code that produces the same error message. I am running in VSCode, PHP Version 7.3.9, and R-3.6.2. Below are shelled our versions of my code that demonstrate my issue.
index.php
<?php
$R = '"C:/Program Files/R/R-3.6.2/bin/Rscript.exe"';
$testScript = "C:/xampp/htdocs/rtest/testscript.r";
$command = "$R $testScript testingArguement 2>&1";
$result = shell_exec($command);
echo $result;
?>
testscript.r
## Define all libraries
suppressMessages(library(plyr))
suppressMessages(library(dplyr))
suppressMessages(library(tidyr))
suppressMessages(library(tidyselect))
suppressMessages(library(tidyverse))
suppressMessages(library(data.table))
## Suppress Warning Messages
options(warn=-1)
args = commandArgs(trailingOnly=TRUE)
testValue = args[1]
cat("The test value is",testValue)
When I run the command via PHP in VSCode, the result variable receives the following...
"Error in library(plyr) : there is no package called 'plyr'
Calls: suppressMessages -> withCallingHandlers -> library
Execution halted
"
However, if I run the command manually in Command Prompt it works.
C:\Users\Garrett>"C:/Program Files/R/R-3.6.2/bin/Rscript.exe" C:/xampp/htdocs/rtest/testscript.r testingArguement 2>&1
The test value is testingArguement
C:\Users\Garrett>
I am just super confused to why the packages aren't getting recognized when running from within VSCode/PHP