{"id":15966924,"url":"https://github.com/yannrichet/rsession","last_synced_at":"2025-03-15T09:31:47.669Z","repository":{"id":28692649,"uuid":"32212803","full_name":"yannrichet/rsession","owner":"yannrichet","description":"R sessions wrapping for Java","archived":false,"fork":false,"pushed_at":"2025-03-12T15:12:02.000Z","size":116840,"stargazers_count":52,"open_issues_count":3,"forks_count":31,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-12T15:35:34.968Z","etag":null,"topics":["java","r","renjin","rserve"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yannrichet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-03-14T13:19:34.000Z","updated_at":"2025-03-12T15:12:06.000Z","dependencies_parsed_at":"2025-03-12T15:38:11.937Z","dependency_job_id":null,"html_url":"https://github.com/yannrichet/rsession","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannrichet%2Frsession","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannrichet%2Frsession/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannrichet%2Frsession/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannrichet%2Frsession/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yannrichet","download_url":"https://codeload.github.com/yannrichet/rsession/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243713357,"owners_count":20335564,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","r","renjin","rserve"],"created_at":"2024-10-07T18:06:28.136Z","updated_at":"2025-03-15T09:31:43.211Z","avatar_url":"https://github.com/yannrichet.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Java CI with Maven](https://github.com/yannrichet/rsession/actions/workflows/maven.yml/badge.svg)](https://github.com/yannrichet/rsession/actions/workflows/maven.yml)\n\n[![codecov](https://codecov.io/gh/yannrichet/rsession/branch/master/graph/badge.svg)](https://codecov.io/gh/yannrichet/rsession)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.yannrichet/Rsession/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.yannrichet/Rsession)\n\n\n# Rsession: R (3.5+) sessions wrapping for Java (8+) #\n\nRsession provides an easy to use java class giving access to remote or local R sessions.\nThe back-end engine should be:\n\n * \"true\" R (3.5, 3.6 and 4.x), through Rserve (locally spawned automatically if necessary, fully compatible with legacy R),\n * Renjin 3.5 (lower compatibility, but still very good),\n * and R2js, which is on-the-fly R translation to math.js, with lower compatibility and hack-style coding, but full BSD licence.\n\nRsession differs from R2js, Rserve or Renjin as it is a higher level API, and it includes server side startup of Rserve. It is also easier to use as it provides a multi session R engine for all these wrappers, whatever OS.\n\nJRI is another alternative, but it does not provide multi-sessions feature.\n\n## Example Java code ##\n```java\nimport static org.math.R.*;\n...\n \n    public static void main(String args[]) {\n        //Rsession r = new RserveSession(System.out, null, null);\n        //Rsession r = new R2jsSession(System.out, null);\n        Rsession r = new RenjinSession(System.out, null);\n\n        double[] rand = (double[]) r.eval(\"rnorm(10)\"); //create java variable from R command\n\n        //...\n        r.set(\"c\", Math.random()); //create R variable from java one\n\n        r.save(new File(\"save.Rdata\"), \"c\"); //save variables in .Rdata\n        r.rm(\"c\"); //delete variable in R environment\n        r.load(new File(\"save.Rdata\")); //load R variable from .Rdata\n\n        //...\n        r.set(\"df\", new double[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}, \"x1\", \"x2\", \"x3\"); //create data frame from given vectors\n        double value = (double) (r.eval(\"df$x1[3]\")); //access one value in data frame\n\n        //...\n        r.toJPEG(new File(\"plot.jpg\"), 400, 400, \"plot(rnorm(10))\"); //create jpeg file from R graphical command (like plot)\n\n        String html = r.asHTML(\"summary(rnorm(100))\"); //format in html using R2HTML\n        System.out.println(html);\n\n        String txt = r.asString(\"summary(rnorm(100))\"); //format in text\n        System.out.println(txt);\n\n        //...\n        System.out.println(r.installPackage(\"sensitivity\", true)); //install and load R package\n        System.out.println(r.installPackage(\"DiceKriging\", true));\n\n        r.end();\n    }\n```\n## Use it ##\n\n### Using maven: ###\n\nUse this maven dependency:\n\n```xml\n\u003cdependencies\u003e\n...\n    \u003cdependency\u003e\n      \u003cgroupId\u003ecom.github.yannrichet\u003c/groupId\u003e\n      \u003cartifactId\u003eRsession\u003c/artifactId\u003e\n      \u003cversion\u003e3.1.7\u003c/version\u003e\n    \u003c/dependency\u003e\n...\n\u003c/dependencies\u003e\n```\n\n### Using only R2js backend: ###\n\nNo 2nd order dependency required. Only based on Nashorn engine bundled in Java \u003e8, so just add `rsession.jar` in your classpath:\n\n  * https://github.com/yannrichet/rsession/blob/master/dist/rsession.jar\n\nThen instanciate R session using:\n```java\nRsession r = new R2jsSession(System.out,null);\n```\n\n\n### Using only Renjin backend: ###\n\nAdd `rsession.jar:renjin-jar-with-dependencies.jar` in your classpath: \n\n  * https://github.com/yannrichet/rsession/blob/master/dist/rsession.jar\n  * https://github.com/yannrichet/rsession/blob/master/lib/renjin-jar-with-dependencies.jar\n\n\nThen instanciate R session using:\n```java\nRsession r = new RenjinSession(System.out,null);\n...\n```\n\n\n### Using only Rserve backend: ###\n\nInstall R 3.5+ or 4.x from http://cran.r-project.org, then add `rsession.jar:Rserve*.jar:REngine*.jar` in your project classpath:\n\n  * https://github.com/yannrichet/rsession/blob/master/dist/rsession.jar\n  * https://github.com/yannrichet/rsession/blob/master/lib/REngine-2.1.0.jar\n  * https://github.com/yannrichet/rsession/blob/master/lib/Rserve-1.8.1.jar\n  \n\nThen:\n  * start Rserve on localhost `/usr/bin/R CMD /usr/lib/R/library/Rserve/libs/Rserve --vanilla --RS-enable-control --RS-port 6311`, and instanciate R session using:\n      ```java\n      Rsession r = new RserveSession(System.out,null,RserverConf.parse(\"R://localhost:6311\")); \n      ```\n  * or use the auto-spawned Rserve (may fail for exotic configuration):\n      ```java\n      Rsession r = new RserveSession(System.out,null,null);\n      ```\n  * connect to remote Rserve (eg. previously started on 192.168.1.1 with `/usr/bin/R CMD /usr/lib/R/library/Rserve/libs/Rserve --vanilla --RS-enable-control --RS-port 6311`:\n      ```java\n      Rsession r = new RserveSession(System.out,null,RserverConf.parse(\"R://192.168.1.1:6311\"));\n      ```\n\n\n![Analytics](https://ga-beacon.appspot.com/UA-109580-20/rsession)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyannrichet%2Frsession","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyannrichet%2Frsession","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyannrichet%2Frsession/lists"}