Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8142387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:48:11+00:00 2026-06-06T12:48:11+00:00

Here’s the issue: I am using R to run some statistical analysis. The results

  • 0

Here’s the issue:

I am using R to run some statistical analysis. The results of which will eventually be sent to a an embedded swf on the user’s client machine.

To do this, I have PHP execute a shell script to run the R program, and I want to retrieve the results of that program so I can parse them in PHP and respond with the appropriate data.

So, it’s simply:

$output = shell_exec("R CMD BATCH /home/bitnami/r_script.R");
echo $output;  

But, I receive nothing of course, because R CMD BATCH writes to a file. I’ve tried redirecting the output in a manner similar to this question which changes my script to

$output = shell_exec('R CMD BATCH /home/bitnami/raschPL.R /dev/tty');
echo $output; 

But what I get on the console is a huge spillout of the source code, and nothing is echoed.

I’ve also tried this question’s solution in my R script.

tl;dr; I need to retrieve the results of an R script in PHP.

Cheers!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:48:14+00:00Added an answer on June 6, 2026 at 12:48 pm

    Found it, the answer is through Rscript. Rscript should be included in the latest install of R.

    Using my code as an example, I would enter this at the very top of r_script.R

    #!/usr/bin/Rscript --options-you-need
    

    This should be the path to your Rscript executable. This can be found easily by typing

    which Rscript
    

    in the terminal. Where I have –options-you-need, place the options you would normally have when doing the CMD BATCH, such as –slave to remove extraneous output.

    You should now be able to run your script like so:

    ./r_script.R arg1 arg2
    

    Important! If you get the error

    Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") : 
    could not find function "is" 
    

    You need to include the “methods” package, like so:

    require("methods"); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a complete example. I want to forbid using A::set from objects casted
Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur
Here my problem: @Assert\Regex( * pattern=/^[A-Za-z0-9][A-Za-z0-9\]*$/, * groups={creation, creation_logged} * ) I'm using the
Here is the code I'm using inside my AsyncTask DefaultHttpClient httpClient = new DefaultHttpClient();
Here a simple question : What do you think of code which use try
Here is the issue I am having: I have a large query that needs
Here is my code, which takes two version identifiers in the form 1, 5,
Here is the scenario: I'm writing an app that will watch for any changes
Here's my situation: I have a Data Template set up which contains a ToggleButton
Here is a part of my code which sends an email: servidor = smtplib.SMTP()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.