Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recover Rcpp source file

Tags:

r

rcpp

I successfully sourced a cpp file into the R environment using sourceCpp('my_cpp_code.cpp'), but I removed the 'my_cpp_code.cpp' by mistake. It is possible to recover the source code of my_cpp_code.cpp from the R environment?

like image 402
yliueagle Avatar asked Sep 24 '19 09:09

yliueagle


2 Answers

The temporary directory of your R session (tempdir()) will contain a folder named sourceCpp-<architecture>->Rcpp-version> with sub-directories named sourcecpp_<random>. One of these will contain your code (plus the autogenerated code).

like image 73
Ralf Stubner Avatar answered Sep 21 '22 21:09

Ralf Stubner


Maybe. sourceCpp() has a cacheDir argument (defaulting to getOption("rcpp.cache.dir", tempdir())) that specifies a location under which intermediate files, including the original source file, are saved. If the directory hasn't been cleaned up, you should find a folder there named "sourceCpp-<platform-info>" and under there, directories for each sourceCpp call you have done: these will contain the original file.

like image 41
Mikko Marttila Avatar answered Sep 17 '22 21:09

Mikko Marttila