I’m using R for genetic programming with the RGP package. The environment creates functions that solve problems. I want to save these functions in their own .R source files. I can’t for the life of me figure out how. One way I’ve tried is this:
bf_str = print(bf)
save(bf_str,file="MyBestFunction.R"))
bf is simply the best fit function. I’ve tried it also like this:
save(bf,file="MyBestFunction.R"))
The outputted file is super weird. Its just a bunch of crazy characters
The way I understand your question, you’d like to get a text representation of the functions and save that to a file. To do that, you can divert the output of the R console using the
sinkfunction.Then you can
sourcethe file or open it using R or another program via your OS.EDIT:
To append a comment to the end of the file, you could do the following:
Depending on your setup, you might need to change
\r\nto reflect the appropriate end of line characters. This should work on DOS/Windows at least.