as.list is implemented for java objects and java arrays to facilitate using lapply calls over elements of a java array or items of an Iterator associated with an Iterable object

For java array references, as.list is mapped to .jevalArray

For java objects that implement the Iterable interface, the list is created by iterating over the associated iterator

# S3 method for class 'jobjRef'
as.list(x, ...)
# S3 method for class 'jarrayRef'
as.list(x, ...)

Arguments

x

java array or Iterable java object

...

ignored

Value

An R list, or vector.

Note

The function is not intended to be called directly. It is implemented so that java arrays or Iterable java objects can be used as the first argument of lapply

See also

Examples

  # lapplying over a java array
  a <- .jarray( list( 
  .jnew( "java/awt/Point", 10L, 10L ), 
  .jnew( "java/awt/Point", 30L, 30L )
  ) )
  lapply( a, function(point){ 
  with(point, { 
    (x + y ) ^ 2
  } )
  } )
#> [[1]]
#> [1] 400
#> 
#> [[2]]
#> [1] 3600
#> 

# lapply over a Vector (implements Iterable)
v <- .jnew("java/util/Vector")
v$add( "foo" )
#> [1] TRUE
v$add( .jnew("java/lang/Double", 10.2 ) )
#> [1] TRUE
sapply( v, function(item) item$getClass()$getName() )
#> [1] "java.lang.String" "java.lang.Double"