Is there a definitive way to save options or information pertaining to a certain package between sessions?
For example say somebody made a game and released it as an R package. If they wanted to save high scores and not have them reset each time R started a new session what would be the best way to do this? Currently I can only think of storing a file in the users home directory but I’m not sure if I like that approach.
This may be an approach. I created a dummy package with a dummy function (any function I create is bound to be a dummy function) and a data set I called
scoresthat I set as follows:Then I created the package with the scores data set.
Then I used the following to change the data set from within R.
Then when I unloaded the library and re loaded agin the data set now says:
Could this be modified to do what you want? You’d have to have it save in between somehow but am not sure on how to do this without messing with
.Lastfunction.EDIT:
It appears this option is not viable in that when you compile as a package and use lazy load it saves the data sets as:
RData.rbd, RData.rbx, not as .rda files. That means the approach I use above is kinda worthless in that we want it to automatically be recognized.
EDIT2
This approach works and I tried it on a package I made. You can’t do lazy load of the data and you have to either explicitly use
data(scores)or usedata(scores)inside of the function you’re calling. I also assignedscoresto.scoresint he global.env the first time it was created and usedexistsinside the function to see if it exists. If `.scores. existed I assigned that to scores within the function. Once you unload the library and laod again you never have to worry about that again.Maybe an alternative is to save this as a function somehow that can be altered using Josh’s advice here: Permanently replacing a function