Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# rSharp (development version)

- Arrays of .NET objects are now supported as arguments to methods.

# rSharp 1.1.2

## Minor improvements and bug fixes
Expand Down
7 changes: 7 additions & 0 deletions R/rSharp-internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@
if (inherits(args[[i]], "NetObject")) {
args[[i]] <- args[[i]]$pointer
}
# Check if the entry is a list. If so, check if the first element is a NetObject
# and axtract the pointers for all elements
if (is.list(args[[i]]) && length(args[[i]]) > 0) {
if (inherits(args[[i]][[1]], "NetObject")) {
args[[i]] <- lapply(args[[i]], function(x) x$pointer)
}
}
}
return(args)
}
20 changes: 20 additions & 0 deletions tests/testthat/test-net-object.R
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,23 @@ test_that("Deprecated printing methods show appropriate warnings", {
class = "lifecycle_warning_deprecated"
)
})

test_that("A NetObject can be passed as argument to callStatic", {
testObj <- newObjectFromName(rSharpEnv$testObjectTypeName)

expect_true(callTestCase(
"SingleObjectArgument",
testObj
))
})

test_that("An array of NetObjects can be passed as argument to callStatic", {
testObj1 <- newObjectFromName(rSharpEnv$testObjectTypeName)
testObj2 <- newObjectFromName(rSharpEnv$testObjectTypeName)
testArray <- array(c(testObj1, testObj2), dim = c(2))

expect_true(callTestCase(
"ArrayOfObjectsArgument",
testArray
))
})
2 changes: 1 addition & 1 deletion vignettes/user-guide.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ to interact with these objects through the `NetObject`. If, for any reason,
the user needs to access the raw pointer, it can be done by accessing the field
`$pointer` of the R6 object.

`NetObject` instances can be passed to .NET methods as arguments.
`NetObject` instances can be passed to .NET methods as arguments. If a method expects an array of .NET objects, all objects within the R list must be instances of `NetObject`. Mixed lists of native R types and `NetObject` instances are not supported.

## Loading an assembly

Expand Down
Loading