I have been using the splinefun
function in R
to create a smooth interpolation between some data x
and y
. For example:
x <- 1:10
y <- x^2
f <- splinefun(x, y)
f(seq(1, 10, by = 0.1))
Now assume that obtaining y
from x
is time-consuming. The two highly-related questions are:
How can I save and load the function
f
from oneR
session to another without re-evaluating (or re-reading from a table)x
andy
?How can I include
f
as part of anR
package without evaluating/reading in each loadx
andy
?
I know that this changed from R 3.0.0
and now f
is saved inside a specific environment
environment(f) # <environment: 0x1036daf80>
and has the bytecode <bytecode: 0x1036e0748>
, but no idea what to do with that.