-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Public Method for Accessing Private Attributes in text_definition
#13
Comments
It looks like neither I would suggest to define an active binding to access the entries. This way, you can write |
The same can be done for the Lines 17 to 25 in fc44a39
|
I'm a bit lost on where would you add this @zkamvar , if you can show me with a small example I would be grateful. |
Active bindings are another part of the R6 class that act like publicly available list elements that auto-compute their contents. I realized that I accidentally linked the wrong content 😳, so here's the link to the documentation: https://r6.r-lib.org/articles/Introduction.html#active-bindings-1. Thank you for asking for clarification! With active bindings, you can write They are defined in the R6 class with by defining a list to the LanguageGlossaryEntry <- R6::R6Class("LanguageGlossaryEntry",
private = list(
.lang = NA_character_,
.term = NA_character_,
.defn = NA_character_
),
# ---------------------- Active bindings can be accessed just like list read-only elements
active = list(
language = function() {
private$.lang
},
term = function() {
private$.term
},
definition = function() {
private$.defn
}
),
# -----------------------------------------------
public = list(
initialize = function(term, defn, lang = "en") {
stopifnot(rlang::is_scalar_character(term))
stopifnot(rlang::is_scalar_character(defn))
stopifnot(rlang::is_scalar_character(lang))
private$.term <- term
private$.defn <- defn
private$.lang <- lang
}
print = function(show_lang = TRUE) {
def <- private$.defn
if (show_lang) {
def <- paste0(def, " (", private$.lang, ")")
}
names(def) <- private$.term
cli::cli_dl(def)
}
)
) For GlossaryEntry, you would do something similar and add: # <snip>
private = list(
.slug = NA_character_,
.entries = NULL,
.ref = NULL
),
active = list(
slug = function() {
private$.slug
},
entries = function() {
private$.entries
},
refrence = function() {
private$.ref
}
),
# <snip>
Hope that helps and sorry for the confusion! |
In
R/text_definition.R
line 7. I'm currently doing the following:@zkamvar suggested in #11 that we add a public method instead of accessing the enclosed environment. This issue is to discuss and track this development.
The text was updated successfully, but these errors were encountered: