Skip to content

Instantly share code, notes, and snippets.

@thospfuller
Created January 30, 2022 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thospfuller/ff86fc7bf9643dd71c7257b8598e5059 to your computer and use it in GitHub Desktop.
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
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