Search code examples
rconsoledataframewrite.table

R console doesn't respond to code changes


R console sometimes acts very strangely when I paste code and execute in it. After executing code that creates an output file, the console from then on will only generate that specific output, regardless if I make changes to the code.

The problem can be explained using the below code as an example. dataframeA and dataframeB are the contents of two csv format spreadsheets read in with read.csv

>CombinedCols <- data.frame(dataframeA, dataframeB) 
>write.table(CombinedCols, file = "/Users/Username/Results.csv",
              append = TRUE, sep = ",") 

When I change the contents of dataframeA or dataframeB and re-execute the code in console the file Results.csv would be generated exactly as if I had made no changes to dataframeA or B.

I have no idea what this situation is even called. Does anyone have any insight about what the issue is here?


Solution

  • By combining dataframe A and B, a new object CombinedCols is created. After that, there is no link between CombinedCols and its original objects, dataframe A and B. Therefore, any changes in dataframe A is not reflected in CombinedCols.

    In order for the changes in data frame A to be reflected in CombinedCols, you need re-create it with the new, edited, data frames.