diff --git a/R/class-workbook-wrappers.R b/R/class-workbook-wrappers.R index 794e6afa3..9b83bdd57 100644 --- a/R/class-workbook-wrappers.R +++ b/R/class-workbook-wrappers.R @@ -2974,6 +2974,11 @@ wb_add_thread <- function( reply = FALSE, resolve = FALSE ) { + + if (missing(person_id)) { + person_id <- substitute() + } + assert_workbook(wb) wb$clone()$add_thread( sheet = sheet, diff --git a/R/class-workbook.R b/R/class-workbook.R index 457964ee4..494a54f0f 100644 --- a/R/class-workbook.R +++ b/R/class-workbook.R @@ -3746,6 +3746,11 @@ wbWorkbook <- R6::R6Class( resolve = FALSE ) { + if (missing(person_id)) { + person_id <- getOption("openxlsx2.thread_id") + if (is.null(person_id)) stop("no person id found") + } + sheet <- self$validate_sheet(sheet) wb_cmt <- wb_get_comment(self, sheet, dims) @@ -6874,6 +6879,8 @@ wbWorkbook <- R6::R6Class( ) ) + options("openxlsx2.thread_id" = id) + if (is.null(self$persons)) { self$persons <- xml_node_create( "personList", diff --git a/tests/testthat/test-class-comment.R b/tests/testthat/test-class-comment.R index 06fcc9ea1..b1675381f 100644 --- a/tests/testthat/test-class-comment.R +++ b/tests/testthat/test-class-comment.R @@ -236,3 +236,15 @@ test_that("threaded comments work", { expect_equal(exp, got) }) + +test_that("thread option works", { + + wb <- wb_workbook()$add_worksheet() + wb$add_person(name = "Kirk") + wb <- wb %>% wb_add_thread(comment = "works") + + exp <- "works" + got <- wb_get_thread(wb)$text + expect_equal(exp, got) + +})