AccessMutate.JuliaProxy {JuliaConnectoR} | R Documentation |
Access or mutate Julia objects via proxy objects
Description
Apply the R operators $
and $<-
, [
and [<-
, [[
and [[<-
to access or modify parts of Julia objects via their proxy objects.
For an intuitive understanding, best see the examples below.
Usage
## S3 method for class 'JuliaStructProxy'
x$name
## S3 replacement method for class 'JuliaStructProxy'
x$name <- value
## S3 method for class 'JuliaProxy'
x[...]
## S3 replacement method for class 'JuliaProxy'
x[i, j, k] <- value
## S3 method for class 'JuliaSimpleArrayProxy'
x[...]
## S3 method for class 'JuliaArrayProxy'
x[[...]]
## S3 replacement method for class 'JuliaArrayProxy'
x[[i, j, k]] <- value
## S3 method for class 'JuliaStructProxy'
x[[name]]
## S3 replacement method for class 'JuliaStructProxy'
x[[name]] <- value
## S3 method for class 'JuliaArrayProxy'
length(x)
## S3 method for class 'JuliaArrayProxy'
dim(x)
Arguments
x |
a Julia proxy object |
name |
the field of a struct type, the name of a member in a |
value |
a suitable replacement value. When replacing a range of elements in an array type, it is possible to replace multiple elements with single elements. In all other cases, the length of the replacement must match the number of elements to replace. |
i , j , k , ... |
index(es) for specifying the elements to extract or replace |
Details
The operators $
and [[
allow to access properties of Julia struct
s
and NamedTuple
s via their proxy objects.
For dictionaries (Julia type AbstractDict
), $
and [[
can also be used to look up string keys.
Fields of mutable struct
s and dictionary elements with string keys
can be set via $<-
and [[<-
.
For AbstractArray
s, the [
, [<-
, [[
, and [[<-
operators relay to the getindex
and setindex!
Julia functions.
The [[
and [[<-
operators are used to access or mutate a single element.
With [
and [<-
, a range of objects is accessed or mutated.
The elements of Tuple
s can also be accessed via [
and [[
.
The dimensions of proxy objects for Julia AbstractArray
s and Tuple
s
can be queried via length
and dim
.
Examples
## Not run: #'
# (Mutable) struct
juliaEval("mutable struct MyStruct
x::Int
end")
MyStruct <- juliaFun("MyStruct")
s <- MyStruct(1L)
s$x
s$x <- 2
s[["x"]]
# Array
x <- juliaCall("map", MyStruct, c(1L, 2L, 3L))
x
length(x)
x[[1]]
x[[1]]$x
x[[1]] <- MyStruct(2L)
x[2:3]
x[2:3] <- MyStruct(2L)
x
# Tuple
x <- juliaEval("(1, 2, 3)")
x[[1]]
x[1:2]
length(x)
# NamedTuple
x <- juliaEval("(a=1, b=2)")
x$a
# Dictionary
strDict <- juliaEval('Dict("hi" => 1, "hello" => 2)')
strDict
strDict$hi
strDict$hi <- 0
strDict[["hi"]] <- 2
strDict["howdy", "greetings"] <- c(2, 3)
strDict["hi", "howdy"]
## End(Not run)