Suddenly, R Studio has been giving me hard-to-reproduce errors in which it references old variable names and code that no longer exist in my script. Here is a short replicable example:
LoadInfectionsDrugs <- function() {
}
meta <- read.csv("tblhctmeta.csv")
infections <- read.csv("tblInfectionsCidPapers.csv")
drugs <- read.csv("tbldrug.csv")
workspace <- "w4v3.RData"
load(workspace)
print(head(input))
print(head(meta))
print(head(drugs))
print(head(infections))
LoadInfectionsDrugs() #This line generates the error - loads and prints correctly if this is commented out.
If I comment out the last line, it runs and prints just fine. If I leave the last line in, though, I get the error "Error in unique(input$PatientID): argument "input" is missing, with no default.
Thing is, the LoadInfectionsDrugs function used to (and normally does) have several arguments, including "input", which is a data frame with a column called PatientID. So this clearly seems to be referencing old code.
If I comment out the "load(workspace)" and "print(head(input))" lines, it also runs fine.
So my hypothesis is that, in my main code, when I call "save.image(workspace)", it is saving not only objects, such as the dataframes I'm creating, but also functions. Then, when I change the function in code, but load the workspace, it is replacing the functions I've defined in code with the definitions as they were when I last saved the workspace.
I didn't know that .RData files saved function definitions. I thought they just saved variables. Is there a way to save only the objects you've defined (i.e. dataframes), and not the functions?