I would like to know what's causing my problem. Whenever I write anything related to updated_origin in Excel.(Example: writeData(wb,"sheet3",x = multiply,xy = c(c,r+2)) It will always give me this result. (917636 (at row 6, column 3) is supposed to be in (row 5, column 3) and the value 2 in column 4 is wrong.)
Code when I use values related to updated_origin Excel output when I used values relatd to updated_origin
However, when I write anything unrelated to updated_origin (example, writeData(wb,"sheet3",x =column_sum,xy = c(c,r+2)). I will get my desired result.
Code for desired result Excel output when using values not related to updated_origin
Below is the code:
addWorksheet(wb,"sheet3")
writeData(wb,"sheet3",x = filtered_triangle)
saveWorkbook(wb, "testing.xlsx", overwrite = TRUE)
origin <- read_excel("testing.xlsx","sheet2",skip = 1)
origin[] <- lapply(origin,as.numeric)
updated_origin <- read_excel("testing.xlsx","sheet3",skip = 1)
updated_origin[] <- lapply(updated_origin,as.numeric)
r <- 1
c <- 2
while(c <= ncol(origin)-1){
while(r <= nrow(origin)){
#column_sum <- sum(origin[,c],na.rm = TRUE)
multiply <- read_excel("testing.xlsx","sheet3",skip = 1)[r,c-1]
#column_divide <- sum(origin[,c-1],na.rm = TRUE)-multiply
#cumulative <- column_sum*multiply/column_divide
if(is.na(origin[r,c])){
writeData(wb,"sheet3",x = multiply,xy = c(c,r+2))
saveWorkbook(wb, "testing.xlsx", overwrite = TRUE)
}
r <- r+1
}
c <- c+1
r <- 1
}
saveWorkbook(wb, "testing.xlsx", overwrite = TRUE)
The code is use to replicate this function in Rshiny
At first I thought maybe xy = c(c,r+2) from writeData(wb,"sheet3",x = multiply,xy = c(c,r+2) was the problem. But it still doesn't help when changing it.