WARNING: This is very limited proof of concept!

# S3 method for CFunc
marshal(inline, ...)

# S3 method for CFunc
marshallable(...)

Arguments

inline

A CFunc function.

...

Not used.

Value

A marshalled object as described in marshal().

Details

Currently, it is only possible to marshal a function:

  • of class CFunc that was created without "includes" or "otherdefs"

Examples

if (requireNamespace("inline", quietly = TRUE)) {
  code <- "
    int i;  
    for (i = 0; i < *n; i++) x[0] = x[0] + (i+1);  
  "
  sum_1_to_n <- inline::cfunction(
    signature(n = "integer", x = "numeric"),
    code,
    language = "C", convention = ".C"
  )

  ## Marshal CFunc function
  sum_1_to_n_ <- marshal(sum_1_to_n)

  ## Unarshal CFunc function
  sum_1_to_n2 <- unmarshal(sum_1_to_n_)

  y <- sum_1_to_n(10, 0)$x
  print(y)

  y2 <- sum_1_to_n2(10, 0)$x
  print(y2)
}
#> [1] 55
#> [1] 55