Can't load R libraries using RScript command in PHP

one text

I am trying to connect my R script with my PHP/HTML code. I'm quite well-versed in R but a novice in PHP. My R code requires the use of packages that the PHP command will not load.

Here is the R script:

print(Sys.time()) 
library(tinytest, lib.loc = c(".../R/R-4.2.1/library","...www\\mypage")) 
print("worked")

And here is the sample PHP script:

<?php
echo "Testing";
echo shell_exec  ("Rscript /.../www/mypage/my_script.R");
?>

What ends up being printed is as follows:

Testing [1] "xxxx-xx-xx xx:xx:xx EDT"

The PHP and R scripts are saved in the same www location. R is installed on the computer.

I've tried a variety of solutions on both R and PHP:

For R:

  1. Running .libPaths() on R to identify where the library paths are.
  2. Adding that library path to the install.packages and library function calls.
  3. Installing all of my packages to the www location and added that to lib.loc in my library and install.packages calls.
  4. Adding the dependencies = TRUE on install.packages
  5. Manually installing each and every dependency on all locations
  6. Manually calling each library by name
  7. Ran print(cat(capture.output(file.info("xxx/xxx/xxx")), file = stderr())) to make sure that R has permissions to read the downloaded libraries
  8. I tried setting the working directory, but PHP would error out
  9. I used "Sys.getenv('R_LIBS_USER')" to get the current directory and used that to no avail

For PHP:

  1. I tried using the Rscript command and its full directory path to the file
  2. I ruled it out being an RScript issue by locating my R.exe and Rscript.exe files
  3. I tried using the "--default-packages =" command through Rscript (got an error)
  4. I tried using this commonly posted solution but to no avail

I have tried many solutions but these are the ones I suspect:

  1. Permissions issues: I am not the administrator on this computer
  2. Some sort of directory path/library read issue

I'm not sure what else I can do. I could try and look into Apache and RServe, but some permissions issues make it difficult. I've looked into a lot of stackoverflow questions around this topic, but still am unable to solve it. Any ideas?

I am running R version 4.2.1, Windows 10, and PHP version 5.4.16.

Source