Skip to content

RMongo messes the R script output stream #47

@rootkea

Description

@rootkea

my_script.R:

#!/usr/bin/env Rscript

i <- as.numeric(commandArgs(TRUE))
print(i:10)

index.php

<?php
    $n = 3;
    exec("Rscript my_script.R $n", $out);
    var_dump($out);
<?

Output:

array(1) { [0]=> string(27) "[1] 3 4 5 6 7 8 9 10" } 

Shell Output:

$ Rscript my_script.R 3
Loading required package: rJava
Loading required package: methods
[1]  3  4  5  6  7  8  9 10

Now I need to have the database connection and other processing in my_script.R before I print the result. So
Modified my_script.R:

#!/usr/bin/env Rscript

i <- as.numeric(commandArgs(TRUE))
rootkea <- mongoDbConnect('rootkea')
print(i:10)

Output:

array(0) { }

Shell Output:

$ Rscript my_script.R 3
Loading required package: rJava
Loading required package: methods
[1]  3  4  5  6  7  8  9 10

Though I get the shell output as expected, RMongo messes something with php. How do I make RMongo not mess up with the value returned in $out argument?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions