0

I'm trying to save data in a file, but every time I hit the save button, it saves it but keeps deleting the data I already have there. What could be the problem?

 saveData <- function(data) { data <- as.data.frame(t(data)) if (exists("responses")) { responses <<- rbind(responses, data) } else { responses <<- data } write.csv(responses, file = "read.csv", row.names = FALSE) 
1
  • add append = TRUE to write.csv and check ?write.csv. Commented Feb 18, 2018 at 8:25

1 Answer 1

2

Use

write.csv(responses, file = "read.csv", row.names = FALSE, append = TRUE) 

Or

saveData <- function(data) { data <- as.data.frame(t(data)) write.csv(data, file = "read.csv", row.names = FALSE, append = TRUE) 
Sign up to request clarification or add additional context in comments.

1 Comment

You can avoid checking the response object if you write the csv with append = TRUE.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.