Formatting and comments can be added using the openxlsx
package. For example:
library(openxlsx)
# writing the data to a new workbook
wb <- createWorkbook()
addWorksheet(wb, "Sheet1")
writeData(wb, 1, df)
# apply to all cells with NAs:
apply(which(is.na(df), arr.ind = T), MARGIN = 1, FUN = function(cell) {
# overwrite the missing value
writeData(wb, 1,
sample(1:3, 1), # your interpolated value (here a random number)
startRow = cell['row']+1, startCol = cell['col']
)
# highlight the cell
addStyle(wb, 1,
createStyle(fgFill = 'orange'),
rows = cell['row']+1, cols = cell['col']
)
# add a comment to the cell
writeComment(wb, 1, col = cell['col'], row = cell['row']+1,
comment = createComment("Filled in with random number")
)
}) %>% invisible
# view the workbook (there's also a function for saving it to disk)
openXL(wb)