Skip to content

Commit

Permalink
Don't run example for AccessMutate.JuliaProxy. Use test instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-m-lenz committed Dec 6, 2023
1 parent 891b10c commit e357b4a
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 93 deletions.
80 changes: 36 additions & 44 deletions R/accessing_mutating.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,56 +33,48 @@
#' the length of the replacement must match the number of elements to replace.
#' @name AccessMutate.JuliaProxy
#' @examples
#' if (juliaSetupOk()) {
#' \dontrun{#'
#' # (Mutable) struct
#' juliaEval("mutable struct MyStruct
#' x::Int
#' end")
#'
#' # (Mutable) struct
#' juliaEval("mutable struct MyStruct
#' x::Int
#' end")
#' MyStruct <- juliaFun("MyStruct")
#' s <- MyStruct(1L)
#' s$x
#' s$x <- 2
#' s[["x"]]
#'
#' 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
#'
#' # 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)
#'
#' # Tuple
#' x <- juliaEval("(1, 2, 3)")
#' x[[1]]
#' x[1:2]
#' length(x)
#' # NamedTuple
#' x <- juliaEval("(a=1, b=2)")
#' x$a
#'
#' # 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"]
#'
#' # 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"]
#'
#' }
#'
#' \dontshow{
#' if (exists("strDict")) {
#' rm(x, s, strDict)
#' }
#' stopJulia()
#' }
NULL

Expand Down
90 changes: 41 additions & 49 deletions man/AccessMutate.JuliaProxy.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions tests/testthat/test_examples_notrun.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
test_that("Example for AccessMutate.JuliaProxy works", {
# (Mutable) struct
juliaEval("mutable struct MyStruct
x::Int
end")

MyStruct <- juliaFun("MyStruct")
s <- MyStruct(1L)
s$x
s$x <- 2
expect_equal(s[["x"]], 2)


# Array
x <- juliaCall("map", MyStruct, c(1L, 2L, 3L))
x
expect_equal(length(x), 3)
x[[1]]
x[[1]]$x
x[[1]] <- MyStruct(2L)
x[2:3]
x[2:3] <- MyStruct(2L)
expect_equal(juliaLet("[myx.x for myx in x]", x = x), c(2,2,2))

# Tuple
x <- juliaEval("(1, 2, 3)")
expect_equal(x[[1]], 1)
expect_s3_class(x[1:2], "JuliaProxy")
expect_equal(length(x), 3)

# NamedTuple
x <- juliaEval("(a=1, b=2)")
expect_equal(x$a, 1)

# Dictionary
strDict <- juliaEval('Dict("hi" => 1, "hello" => 2)')
strDict
expect_equal(strDict$hi, 1)
strDict$hi <- 0
strDict[["hi"]] <- 2
strDict["howdy", "greetings"] <- c(2, 3)
expect_equal(strDict["hi", "howdy"], list(2,2))

})

0 comments on commit e357b4a

Please sign in to comment.