Can R identify commented excel cells?

I have an excel.xlsx sheet that has some commented cells in it. After importing into R, is there a way R can identify commented cells? Because I have to use some if else conditions only for commented cells.

+4
source share
1 answer

Let's say we have this file test.xlsx: enter image description here

Using openxlsx, we can read the book as a dataframe object to retrieve only data:

library(openxlsx)

# read the data
df1 <- read.xlsx("test.xlsx")
df1
#    1  no
# 1  2 yes
# 2  3  no
# 3  5  no
# 4 10 yes

If we need to extract comments, we need to read as an object of the book:

# read as workbook object
wb <- loadWorkbook("test.xlsx")

Check the structure of the object to see where the cell reference is stored:

str(wb$comments)
# List of 3
# $ :List of 2
# ..$ :List of 5
# .. ..$ ref       : chr "B2"
# ...
# ... etc

, :

lapply(wb$comments, function(sheet)
  sapply(sheet, "[[", "ref"))
# [[1]]
# [1] "B2" "B5"
# 
# [[2]]
# list()
# 
# [[3]]
# list()

, 3 , 1- 2 B2 B5, 2 .

+6

Source: https://habr.com/ru/post/1694879/


All Articles