awalker89 / openxlsx

R package for .xlsx file reading and writing.
Other
364 stars 79 forks source link

NA is not handled correctly for class hyperlink #370

Closed kbzsl closed 6 years ago

kbzsl commented 6 years ago

Expected Behavior

to create a hyperlink for each cell containing an URL string but to leave the empty (NA) cells empty and without any hyperlink

Actual Behavior

in case of the missing data (NA) the hyperlink from the consecutive cell is inserted erroneously for the empty cell and the hyperlinks are rolled in advance for every consecutive cell (check the hyperlinks from the last line)

Steps to Reproduce the Problem

(please attach an example xlsx file if possible)

  1. code to reproduce the fault

    table <- tribble(
      ~amazon, ~ebay, ~rakuten,
      "https://www.amazon.com/", "https://www.ebay.com/", "https://www.rakuten.com/",
      "https://www.amazon.com/", "https://www.ebay.com/", "https://www.rakuten.com/",
      "https://www.amazon.com/", NA, "https://www.rakuten.com/",
      "https://www.amazon.com/", "https://www.ebay.com/", "https://www.rakuten.com/"
    )
    
    class(table$amazon) <- "hyperlink"
    class(table$ebay) <- "hyperlink"
    class(table$rakuten) <- "hyperlink"
    
    wb <- createWorkbook()
    addWorksheet(wb, "url")
    writeDataTable(wb, "url", table, tableName = "url")
    freezePane(wb, "url", firstRow = TRUE) 
    saveWorkbook(wb, file = "fault.xlsx", overwrite = TRUE)

image

3.

sessionInfo()

awalker89 commented 6 years ago

Thank you for the reproducible example.