I'm writing an R package which, among other things, defines a function which is actually a wrapper for a PHP script. Let's assume the PHP script offers some functionality that is considerably difficult to recreate in R and that my line of reasoning (wrapping a PHP script in R) makes sense.
I'm currently keeping the PHP script in a separate file, and running it via a system call.
My R function/wrapper looks like this:
wrapper <- function() {
# I'm not entirely sure what the path to the PHP file should be
php_file_name <- "magic_in.php"
php_script_argument <- "hello, world"
system_call <- sprintf('php -f "%s"', php_file_name, php_script_argument)
system(system_call)
}
while the magic_in.php
file is the following:
<?php
print($argv[1]."
")
?>
But this solution sucks - the system call works only if I have the PHP script in my current working directory.
I keep the wrapper in a ~/simple_package/R/wrapper.R
file, but I'm not sure where to store the PHP script.
Am I supposed to keep the PHP file in a ~/simple_package/src
directory and then call it using some dedicated R function (like .Call
for C executables)?