convertToJava: Convert R Objects to Java Objects

Description Usage Arguments Details Value See Also Examples

View source: R/Public.R

Description

The function convertToJava converts R objects to generic Java objects for use with the rJava package. This function simplifies and extends data exchange for rJava. The function convertToJava is the inverse of convertToR.

Usage

1
2
3
4
5
6
7
8
convertToJava(
  value,
  length.one.vector.as.array = FALSE,
  scalars.as.objects = FALSE,
  array.order = "row-major",
  data.frame.row.major = TRUE,
  coerce.factors = TRUE
)

Arguments

value

An R vector, matrix, n-dimensional array, table, factor, data frame, list, or environment. Nested lists are supported. Supported data types: numeric, integer, character, logical, and raw.

length.one.vector.as.array

A logical vector of length one. See R Vectors of Length One in the vignette.

scalars.as.objects

A logical vector of length one. See R Vectors of Length One in the vignette.

array.order

A character vector of length one specifying the order when copying R n-dimensional arrays to Java. Valid values are "row-major", "column-major", and "column-minor". See R Matrices and N-dimensional Arrays in the vignette.

data.frame.row.major

A logical vector of length one. When TRUE (the default), a data frame is converted to a list of map objects that represent rows. When FALSE, a data frame is converted to a map of arrays that represent columns. Conversion for column-major order is much faster than row-major order. See R Data Frames in the vignette.

coerce.factors

A logical vector of length one. When TRUE (the default), an attempt is made to coerce the character values backing factors to integer, numeric, or logical vectors. If coercion fails, the factor is converted to a character vector. When FALSE, the factor is converted to a character vector. This parameter affects standalone factors as well as factors present in data frames and lists. See R Factors in the vignette.

Details

The convertToJava function is used to create objects that can be used as method parameters in the rJava package. R vectors, matrices, n-dimensional arrays, tables, factors, data frames, environments, lists, named lists, and nested lists are supported as well as data types numeric, integer, logical, character and raw.

The vignette contains all documentation for convertToJava and its inverse function convertToR. Note that these functions are not always perfect inverses of each other. See Conversion Issues for more information.

Value

A Java object reference or an R vector. See the vignette for details.

See Also

convertToR , getJavaClassName

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
library("jdx")

# Convert matrix using column-major ordering
m <- matrix(1:4, 2, 2)
o = convertToJava(m, array.order = "column-major")
getJavaClassName(o)
identical(m, convertToR(o, array.order = "column-major"))

# Convert 4-dimensional array using row-major ordering
dimensions <- c(3, 2, 2, 2)
a = array(1:prod(dimensions), dimensions)
o = convertToJava(a, array.order = "row-major")
getJavaClassName(o)
identical(a, convertToR(o, array.order = "row-major"))

# Convert data frame
identical(iris, convertToR(convertToJava(iris)))

# Demonstrate exact double precision
identical(pi, convertToR(convertToJava(pi, scalars.as.objects = TRUE)))

Example output

[1] "[[I"
[1] TRUE
[1] "[[[[I"
[1] TRUE
[1] FALSE
[1] TRUE

jdx documentation built on July 2, 2020, 2:12 a.m.