0

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:

  1. How can I save and load the function f from one R session to another without re-evaluating (or re-reading from a table) x and y?

  2. How can I include f as part of an R package without evaluating/reading in each load x and y?

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.

epsilone
  • 745
  • 11
  • 23
  • You can use a physical cash decorator. The name of the cache will be a hash of the function argument (here the function is splinefun abd arguments are `x` and `y`) – Colonel Beauvel Nov 10 '15 at 11:32
  • @ColonelBeauvel Sorry, but I am not sure to understand what do you mean... Probably because my programming knowledge outside `R` is definitely limited. Could you elaborate on how to make this implementable in `R`? – epsilone Nov 10 '15 at 22:14

0 Answers0