How to execute two different R script under a single session of Microsoft R server 9.0.1? RRS feed

  • Question


    I have two R script 1) add  2)multiply exposed as services.

    publishService(   "add",
        code = "result <- x + y",
        inputs = list(x = "numeric", y = "numeric"),
        outputs = list(result = "numeric"),

    publishService(   "multiply",
        code = "result <- x * y",   
        outputs = list(result = "numeric"),

    In which add function takes two parameter x and y and returns summed output as result.
    Now I have multiply function which has to take the x and y value from the session and perform the multiplication operation.

    I tried to call service with the proxy created by swagger as below.

                AddApi addApi = new AddApi(config);
                var result = addApi.ConsumeWebServiceWithHttpInfo(new InputParameters(5.1M, 2.2M));
                var output = result.Data.OutputParameters.Result;

                MultiplyApi multiplyApi = new MultiplyApi(config);
                result = multiplyApi.ConsumeWebServiceWithHttpInfo(new InputParametersMultiply());
                output = result.Data.OutputParameters.Result;

    I am getting following error in response.

    {"success":false,"errorMessage":"Error in eval(expr, envir, enclos) : object 'x' not found\nresult could not be returned.\r\n","outputParameters":{"result":null},"consoleOutput":"","changedFiles":[]}

    Wednesday, January 11, 2017 11:42 AM

All replies

  • Abilash,

    I haven't worked extensively with the operationalization functionality yet but I believe that you'll need to specify the inputs for the multiply function.

    inputs = list(x = "numeric", y = "numeric"),

    My reading of the error message you've pasted is that "x" was not found because it wasn't passed in. I'm guessing that each web service end point executes in an isolated environment. If you want to share information between the two calls you'll need to pass both parameters into each method.


    Thursday, January 12, 2017 4:50 PM
  • Hello Bob,

    Thanks for helping us out. The intension is to use session. Even though this is simple (sample) issue mentioned above, our intensions is to use session accross 10-15 different R scripts. We want to execute different machine learning algorithms one-after-another (in same session). Yes it is resource heavy, but that is our main requirement. Executing R scripts individually does not help us.




    Friday, January 13, 2017 4:19 AM
  • Thanks for your reply Bob.
    In our project, we are using Microsoft R server 8.0.5 with DeployR
    In which, ExecuteScript method of RProject is used to calls web service and maintain session in subsequent calls.
    Now we are planning for a migration to 9.0 to make use of the latest R runtime 3.3.2
    Feature comparison of 9.0 and 8.x in MSDN(
    points that Sessions Component in 9.0 is equivalent to Projects of 8.x
    PFB the code used in 8.0.5 with RProject to maintain session across calls.
    What would the be the equivalent code for the same in 9.0?
    public void SessionSample()
                String deployrEndpoint = "http://localhost:8050/deployr";
                RClient rClient = RClientFactory.createClient(deployrEndpoint);
                RAuthentication authToken = new RBasicAuthentication("admin", "password");
                RUser rUser = rClient.login(authToken);
                RProject rProject = rUser.createProject();
                //--> ADD CALL
                var inputParam1 = RDataFactory.createNumeric("part1", 1);
                var inputParam2 = RDataFactory.createNumeric("part2", 3);
                ProjectExecutionOptions addOptions = new ProjectExecutionOptions();
                addOptions.rinputs = new List<RData>() { inputParam1, inputParam2 };
                addOptions.routputs = new List<string>() { "result" };
                var execAdd = rProject.executeScript("deployr-add", "SessionSample", "admin", "", addOptions);
                var wpoAdd = execAdd.about().workspaceObjects;
                RNumeric addVec = (RNumeric)wpoAdd[0];
                //--> Multiply CALL
                ProjectExecutionOptions mulOptions = new ProjectExecutionOptions();
                mulOptions.routputs = new List<string>() { "result" };
                var exec = rProject.executeScript("deployr-mul", "SessionSample", "admin", "", mulOptions);
                var wpoMul = exec.about().workspaceObjects;
                RNumeric mulVec = (RNumeric)wpoMul[0];
    Abilash Sekharan

    Friday, January 13, 2017 10:04 AM
  • The equivalent of Projects in 8.0.5 is sessions in 9.0.1

    Please check out the APIs

    You can generate a c# client for the session APIs as described here:

    Friday, January 13, 2017 7:09 PM
  • Hi Daniel Hartl,

    As per the document "Sessions" in 9.0.1 is equivalent to "Projects" in 8.0.5. 

    "Projects" API calls are in lines with repository manager and will ask for the following parameter 

    * script name

    * script Directory

    * scriptAuthor

    * scriptVersion

    * ProjectExecutionOptions options

    But "Sessions" in another hand will take the raw R code to execute. 
    It is not tied up with the repository or the exposed web-api.
    This will beat the purpose of publishService API in 9.0.1.

    Abilash Sekharan

    Tuesday, January 17, 2017 5:32 AM
  • Creating session and using ExecuteCode by passing SessionID works as expected.


    • Proposed as answer by Satyaganti Thursday, May 11, 2017 10:08 AM
    Thursday, May 11, 2017 10:08 AM