Skip to content
Open
Show file tree
Hide file tree
Changes from 9 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
9 changes: 9 additions & 0 deletions R/rSharp-internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@
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 extract 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) {
if (inherits(x, "NetObject")) x$pointer else x
})
}
}
}
return(args)
}
Binary file modified inst/extdata/rSharp.Examples.dll
Binary file not shown.
Binary file modified inst/lib/ClrFacade.dll
Binary file not shown.
Binary file modified inst/lib/DynamicInterop.dll
Binary file not shown.
Binary file modified inst/lib/RDotNet.dll
Binary file not shown.
Binary file modified inst/lib/rSharp.dll
Binary file not shown.
Binary file modified inst/lib/rSharp.mac.arm64.so
Binary file not shown.
19 changes: 19 additions & 0 deletions shared/ClrFacade/TestCases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@ namespace ClrFacade;
// Do not change the names or signatures without also updating usages in R
public class TestCases
{
public static bool SingleObjectArgument(TestObject arg)
{
return arg != null && arg.GetType() == typeof(TestObject);
}

public static bool ArrayOfObjectsArgument(TestObject[] arg)
{
if (arg == null)
return false;

for (var i = 0; i < arg.Length; i++)
{
if (arg[i] == null || arg[i].GetType() != typeof(TestObject))
return false;
}

return true;
}

public static bool GetTrue()
{
return true;
Expand Down
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