Update XLS worksheet without overwriting data using R

4

I need to add new information to the xls worksheet, but it already has information that was previously entered. I need this data to be on the same sheet.

Is it possible to update a spreadsheet without overwriting data that already exists?

I'm using write.xls in the simplest possible way:

write.xlsx(obj, path, sheetName="Dados") 

I tried to use append, but it always overwrites or creates the data on a different sheet. Is there another way to do this?

    
asked by anonymous 23.09.2015 / 03:55

1 answer

3

If your data is not very large, I'd create a function like this:

write.xlsx2 <- function(obj, path, sheetName){
  dados <- read.xlsx(path = path, sheetName = sheetName)
  dados <- rbind(dados, obj)
  write.xlsx(dados, path = path, sheetName = sheetName)   
}
  • I read the data that is already in excel for the R
  • Inside the R, stack the two
  • I write all over again

It's not the safest way, but it should work in most cases.

    
23.09.2015 / 14:59