RWebServices (version 1.36.0)

typeInfo2Java: Create Java-like function signatures from R functions

Description

The typeInfo2Java methods convert functions or TypeInfo structures to a Java-like signature, without coercion to Java types. See createMap to convert functions and coerce arguments.

These functions are primarily for internal use.

Usage

typeInfo2Java(x, ...)

Arguments

x
function with typeInfo already applied, S4 function, or any TypeInfo class.
...
Additional arguments specific to different methods. These are usually funcName (the name of the function) or args (a list of argument names)

Value

An object of RJavaSignature-class, containing return type, function name, and argument type/name as slots with named character vectors.

Details

TypeInfo offers greater flexibility in type specification than can easily be implemented in Java. This function fails with DynamicTypeTest, and treats StrictIsTypeTest as InheritsTypeTest (issuing a warning in the process). See NamedTypeTest-class of TypeInfo for more information.

Examples

Run this code
library(RWebServices)

func <- function( response, predictor ) {
    if ( is.character( predictor )) 
        return( oneWayAnova( response, as.factor( predictor )))
    formula <- as.formula( substitute( response ~ predictor ))
    result <- lm( formula )
    anova( result )
}

## this indirection makes it easier to apply typeInfo
oneWayAnova <- func

typeInfo(oneWayAnova) <-
  SimultaneousTypeSpecification(
    TypedSignature(
      response = "numeric",
      predictor = "factor"),
    returnType = "anova" )

typeInfo2Java(oneWayAnova)

oneWayAnova <- func

typeInfo(oneWayAnova) <-
  SimultaneousTypeSpecification(
    TypedSignature(
      response = "numeric",
      predictor = "factor"),
    TypedSignature(
      response = "numeric",
      predictor = "character"),
    returnType = "anova" )

typeInfo2Java(oneWayAnova)


oneWayAnova <- func

typeInfo(oneWayAnova) <-
  IndependentTypeSpecification(
    response = c("numeric"),
    predictor = c( "factor", "character", "numeric" ),
    returnType = "anova"
  )

typeInfo2Java(oneWayAnova)

oneWayAnova <- func

typeInfo(oneWayAnova) <-
  SimultaneousTypeSpecification(
    TypedSignature(
      response = "numeric",
      predictor = "factor",
      returnType = "matrix"),
    TypedSignature(
      response = "numeric",
      predictor = "character"),
    returnType = "anova" )

typeInfo2Java(oneWayAnova)

oneWayAnova <- func

typeInfo(oneWayAnova) <-
  IndependentTypeSpecification(
    response = c("numeric"),
    predictor = c( "factor", "character", "numeric" ),
    returnType = c("anova")
  )

typeInfo2Java(oneWayAnova)

# Warning about StrictIsTypeTest
oneWayAnova <- func
typeInfo(oneWayAnova) <-
  IndependentTypeSpecification(
    response = StrictIsTypeTest("numeric"),
    predictor = c( "factor", "character", "numeric" ),
    returnType = c("anova")
  )
typeInfo2Java(oneWayAnova)

oneWayAnova <- func
typeInfo(oneWayAnova) <-
  IndependentTypeSpecification(
    response = "numeric",
    predictor = quote( ( length(predictor) == length(response)) && is( predictor, "factor" )),
    returnType = c("anova")
  )
typeInfo2Java(oneWayAnova)

Run the code above in your browser using DataLab