how to call function from r script

May 14, 2015 at 1:52 PM
Edited May 14, 2015 at 1:54 PM
to call a script in r we will execute below code
but when i try to do in vs2013 with following 2 samples, it did not work, anyone can guide me?
first try
            REngine engine = REngine.GetInstance();
var sentiment_R = engine.Evaluate("source('D:\something.R')");
above will return sentiment_R into list as shown below copy from immediate windows
RObjectType = List
    base: RObjectType = List
    Engine: {RDotNet.REngine}
    IsInvalid: false
    IsProtected: true
    Type: List
instead of return a function it return be a list and i cannot assign value to the function from something.R script

second try is copy out everything from something.R to vs2013 the purpose of source code is to analysis text from twitter source as shown in link here
engine.Evaluate("score.sentiment = function(sentences, pos.words, neg.words, .progress='none')" +
 " { require(plyr) require(stringr)" +

  "scores = laply(sentences, function(sentence, pos.words, neg.words)  { " +
    "sentence = gsub('[[:punct:]]', '', sentence)" +
    "sentence = gsub('[[:cntrl:]]', '', sentence)" +
    "sentence = gsub('\\d+', '', sentence)" +
    "sentence = tolower(sentence)" +
    "word.list = str_split(sentence, '\\s+')" +
    "words = unlist(word.list)" +
    "pos.matches = match(words, pos.words) neg.matches = match(words, neg.words)" + 
    "pos.matches = ! neg.matches = ! score = sum(pos.matches) - sum(neg.matches)" +
    "return(score)}, pos.words, neg.words, .progress=.progress )scores.df = data.frame(score=scores, text=sentences)return(scores.df ) } " ) ;
it return me
 : unexpected symbol
hope someone can provide link or solution to me thank in advance :)
May 31, 2015 at 12:37 AM
cannot work. You have a single backslash character. Use:
Probably the same thing with the following, as an aside:
"sentence = gsub('\\d+', '', sentence)" +
besides the whole string you build is not a valid function declaration: you have no semi-colon or newline separator between statements.
var sentiment = engine.GetSymbol("score.sentiment").AsFunction();
You'll find sample code on how to invoke functions for instance in