Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading Excel cell Notes/Comments and writing into r dataframe column

Tags:

r

excel

Issue: I need to read in excel workbook Notes/Comments for data cells as their own data column in R.

Excel Note/Comment screenshot

I have found my way to the Tidyxl package, but I cannot get the script to work when I'm loading the data.

I have started a GitHub thread to reference for input data, Rscript, & what I hope the end product will look like:

Melunome/Excel-Notes-Comments-into-R

like image 439
melCGS Avatar asked Nov 05 '25 14:11

melCGS


1 Answers

The xlsx package supports this as well.

library(xlsx)
library(tidyverse)

wb <- xlsx::loadWorkbook(file = 'test_data_30oct2020 (1).xlsx')

sheets <- getSheets(wb)
sheet <- sheets[[1]]
rows <- getRows(sheet)
cells <- getCells(rows)


comments <- lapply(cells, getCellComment)


read_comments <- comments %>% 
  purrr::discard(is.null)

resp <- vector('list')

for (i in seq_along(read_comments)) {
  
  resp[[i]] <- read_comments[[i]]$getString()
  
}

resp
like image 117
billash Avatar answered Nov 08 '25 09:11

billash