Created
January 30, 2022 23:24
-
-
Save thospfuller/ff86fc7bf9643dd71c7257b8598e5059 to your computer and use it in GitHub Desktop.
An example of the JDataFrame being used to convert data in Groovy into a data frame in the R Project for Statistical Computing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
groovyJars <- list ( | |
"C:/development/projects/rGroovy/groovy.jars/groovy-2.4.5-indy.jar", | |
"C:/development/projects/rGroovy/groovy.jars/ivy-2.4.0.jar" | |
) | |
options(GROOVY_JARS=groovyJars) | |
library(rGroovy) | |
rGroovy::Initialize() | |
script <- paste ( | |
"@Grab(group='com.coherentlogic.r.integration', module='jdataframe-core', version='0.8.5-RELEASE')", | |
"import com.coherentlogic.r.integration.data.frame.JDataFrameBuilder", | |
"def codes = ['WV', 'VA'] as String[]", | |
"def descriptions = ['West Virginia', 'Virginia'] as String[]", | |
"return new JDataFrameBuilder()", | |
".addColumn('Code', codes)", | |
".addColumn('Description', descriptions)", | |
".toJson()", sep="n") | |
json <- rGroovy::Evaluate(groovyScript = script) | |
temp <- RJSONIO::fromJSON(json) | |
tempDF <- as.data.frame(temp) | |
tempDF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment