convertToR: Convert Java Objects to R Objects

Description Usage Arguments Details Value See Also Examples

View source: R/Public.R

Description

The function convertToR converts the Java objects referenced by rJava objects to R objects. The function convertToR is the inverse of convertToJava.

Usage

1
2
3
4
5
convertToR(
  value,
  strings.as.factors = NULL,
  array.order = "row-major"
)

Arguments

value

An rJava object reference.

strings.as.factors

A logical vector of length one specifying whether string vectors are automatically converted to factors when Java objects are converted to R data frames. This parameter is discussed in the vignette under Java Maps.

array.order

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

Details

The convertToR function is not thread-safe. Do not simultaneously call convertToR from different threads in the same process. A thread-safe alternative is presented in the R documentation for convertToRlowLevel.

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

Value

An R object. See the vignette for details.

See Also

convertToJava , 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.