swift_function: Define an R Function with a Swift Implementation

View source: R/swift-function.R

swift_functionR Documentation

Define an R Function with a Swift Implementation

Description

Dynamically define an R function with Swift source code. Compiles and links a shard library with bindings to the Swift function then defines an R function that uses .Call to invoke the library.

Usage

swift_function(
  code,
  env = globalenv(),
  imports = c("Foundation"),
  cache_dir = tempdir()
)

Arguments

code

Source code for the Swift function definition.

env

Environment where the R functions and modules should be made available.

imports

Character vector of Swift frameworks to import.

cache_dir

Directory to use for caching shared libraries. The default value of tempdir() results in the cache being valid only for the current R session. Pass an alternate directory to preserve the cache across R sessions.

Note

Remember that the function need to be public and that you need to put the required ⁠@_cdecl ("…")⁠ decorator before the function definition.


hrbrmstr/swiftr documentation built on Sept. 15, 2023, 12:44 p.m.