Skip to content

Commit

Permalink
provide an option for the id
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Jul 16, 2023
1 parent 8ce04f5 commit 0fcaaed
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions R/class-workbook-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions R/class-workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -6874,6 +6879,8 @@ wbWorkbook <- R6::R6Class(
)
)

options("openxlsx2.thread_id" = id)

if (is.null(self$persons)) {
self$persons <- xml_node_create(
"personList",
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-class-comment.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

})

0 comments on commit 0fcaaed

Please sign in to comment.