R/immutable.R

Defines functions abort_modify_worker `[[<-.jieba_worker` `[<-.jieba_worker` `$<-.jieba_worker`

# Block modifying jieba_worker objects with `$<-`, `[<-` and `[[<-`.
#
# A worker's settings live in its native Rust worker and are fixed when
# worker() creates it. The R object only holds a handle to it and a copy of
# the settings for print(), so assigning into the R object would silently
# change nothing, or break the worker.

#' @export
`$<-.jieba_worker` <- function(x, name, value) {
  abort_modify_worker()
}

#' @export
`[<-.jieba_worker` <- function(x, i, ..., value) {
  abort_modify_worker()
}

#' @export
`[[<-.jieba_worker` <- function(x, i, ..., value) {
  abort_modify_worker()
}

abort_modify_worker <- function(call = rlang::caller_env()) {
  cli::cli_abort(
    c(
      "A {.cls jieba_worker} object can't be modified.",
      i = "Build a new worker with {.fn worker} instead.",
      i = "To add words to its dictionary, use {.fn new_user_word}."
    ),
    call = call
  )
}

Try the jiebaRS package in your browser

Any scripts or data that you put into this service are public.

jiebaRS documentation built on Dec. 3, 2026, 5:09 p.m.