Re: [R] How to run own R functions in JRI
So I copy and pasted my function to the R startup file. However, in my function, I change directories. When I run the function in Eclipse, I get a message in the console, Cannot change working directory. Why is this? -- View this message in context: http://r.789695.n4.nabble.com/How-to-run-own-R-functions-in-JRI-tp2965288p2966910.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to run own R functions in JRI
I guess the best answer to your question depends on the specifics of the implementation, but, i think if I were in your situation and I wanted to be able to call a function foo found in file foo.R every time a user clicked a button, i'd just source(path to foo.R) which just parses the contents of the file as if they were included in the script. So, foo.R could be sourced from any of your other scripts. Just make sure to rm(list = loaded files) so that you dont try to read the same function twice, or you could wrap your source() call in something like if (!grepl(FOO,ls())) { source(path too foo.R) } which will only load if the function isn't already loaded. I guess that could be cause problems if you don't know absolute directory structure, but ?source() may help you figure out if you can use relative paths.. if not, off the top of my head you might be able to discover the path using file.path() I guess if your program installs files to directories in some predictable way, this won't be a problem. -- View this message in context: http://r.789695.n4.nabble.com/How-to-run-own-R-functions-in-JRI-tp2965288p2967140.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to run own R functions in JRI
Nevermind about the previous post. However, I in the retest sample code, I can run my own function in the command line. But, say I am creating a GUI and I want the user to enter the model parameters. How do I, within the java code, explicity call my unique function without going to the console? -- View this message in context: http://r.789695.n4.nabble.com/How-to-run-own-R-functions-in-JRI-tp2965288p2967038.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to run own R functions in JRI
So if I have the R function foo and I have my main method in Java how would I call the method foo? What would be the syntax?: Do I create an REengine first? public static void main(String[] args) { } -- View this message in context: http://r.789695.n4.nabble.com/How-to-run-own-R-functions-in-JRI-tp2965288p2967418.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to run own R functions in JRI
Suppose I have implemented my own R function. How do I call this function in Eclipse using JRI? -- View this message in context: http://r.789695.n4.nabble.com/How-to-run-own-R-functions-in-JRI-tp2965288p2965288.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to run own R functions in JRI
I think the basic answer here is package it, which I did a couple of times but found inconvenient if I was going to change the function fairly often, i've taken a different tact, just including custom functions when R starts, i wrote a function that runs when I start the R session, loading the functions in a given directory Gedit's R plugin handles the Rprofile.conf for me, so thats how I made it automatically load, you could just edit that file and change the value of .start{ } # jcress, fall 2010 # load all of the scripts in a directory (called path) # also, define a new function which parses the content in ls() # so we can clean the session without removing the functions loaded path - ~/.Rstartfiles for (nm in list.files(path, pattern = \\.[RrSsQq]$)) { source(file.path(path, nm)) cat(loading, nm, \n) } cleanls - function(objects){ for (func in list.files(/home/jcress/.Rstartfiles)){ objects[(which(objects == eval(removeext(func] - } objects[which(objects==cleanls)] - return(c(objects[which(objects != )])) } rm(list=cleanls(ls())) -- View this message in context: http://r.789695.n4.nabble.com/How-to-run-own-R-functions-in-JRI-tp2965288p2965473.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to run own R functions in JRI
I am still a little unsure of how I would do this. I do not want to install GEdit. Is there anyway in the retest in the included example that you can show me how I would do this? My function is: lol = function(x,y) { sum = x+y mod = sum %5 return mod } -- View this message in context: http://r.789695.n4.nabble.com/How-to-run-own-R-functions-in-JRI-tp2965288p2965654.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to run own R functions in JRI
Sure, so, all I was saying about gedit is that it handles the R session for me, which is a neat feature but not mandatory to get the expected result, there's an rprofile.site file which describes your (user specific) preferences, you can manually edit this file to add functions at start up by defining a start{} function that's where I put the code in my example, so you could create a directory and use a function similar to the one I posted to load everything in that directory, or just paste functions into your rprofile.site file. for documentation see http://biom1.univ-lyon1.fr/library/base/html/Startup.html -- View this message in context: http://r.789695.n4.nabble.com/How-to-run-own-R-functions-in-JRI-tp2965288p2965795.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.