[Rcpp-devel] Save objects across sessions

soeren.vogel at posteo.ch soeren.vogel at posteo.ch
Tue May 6 09:41:29 CEST 2014


Hello

I am trying to enhance my enhance my Rcpp class with the functionality to be saved across R sessions. For convenience reasons I would like to do that in R, using the ReferenceClass's S4 member function 'finalize()'. My plan is to simply save all object's fields (vectors of various types) to a special list (with a special class name), remove the Rcpp object, and save the plain R object instead. Would that work/be a good option? In particular, what happens on the C++ side if I call rm(reference_object)? Would that remove the C++ side and free its memory? And how can the reverse be accomplished, that is, if an object (identified by its class name) is loaded from a previous session, rebuild the C++ side and form the original reference object?

Sort of finalising:

<art>
x = new( 'Rcpp_Myclass' )
x$finalize() calls:
	x_list = make_my_special_list( x )
	rm( x )
and then the system calls:
gc()
</art>

Sort of loading:

<art>
start_function_?() calls:
	x_lists = look_if_there_is_some_x_lists()
	for every x_list in x_lists:
		name = name_of(x_list)
		name = new( 'Rcpp_Myclass' )
		name$assign_values_from_x_list()
</art>

Thank you for help.

Bests
Sören



More information about the Rcpp-devel mailing list