-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
remove init_chunks in docs #31
Conversation
Code Coverage Summary
Results for commit: e972667 Minimum allowed coverage is ♻️ This comment has been updated with latest results |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR should not be merged till the function is at least depreciated.
@Polkas I don't agree. We shouldn't mention this function at all in the vignette to encourage anyone using this. I don't recommend having init_chunks in the vignette and possibly fix possible occurrences of init_chunks outside of our repos after we fix this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First round of the review, I think we could make it even better.
vignettes/basic_chunks.Rmd
Outdated
|
||
The next sections will explain what a chunk is and how it is evaluated. | ||
|
||
# What is a chunk? | ||
|
||
A quoted R expression is a necessary step to create a **chunk** object. Quoted R expressions can be created in three different ways: | ||
A quoted R expression is a necessary step to create a **chunk** object, which is an R6 object of class `chunk_call`. Quoted R expressions can be created in three different ways: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MAJOR AND IMPORTANT
at least 4 ways, we should point to substitute which we use almost everywhere.
What about rlang
functions which could be used interchangeably. I think it will be nice to give at least one example with rlang next to the base solution.
And with bquote it was not used its biggest advantage, the .()
We have to assume that end users do not understand the meta programming idea.
We could think of a reference to Advanced R Programming (old version) to the proper chapter like http://adv-r.had.co.nz/Computing-on-the-language.html and http://adv-r.had.co.nz/Expressions.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to print the class and I think this markdown-chunk can be limited to this:
A quoted R expression is a necessary step to create a chunk object, which is an R6 object of class chunk_call
. Quoted R expressions can be created in several ways:
quote
when a call is composed as-is.substitute
when a call is composed basing on variables.- Alternatively, one can use
bquote
orrlang::expr
or any function which returns alanguage
(call
,expression
orname
).
# when call is composed as is
quote(a <- 2)
# when call is composed basing on values
substitute(x <- 2, list(x = as.name(a)))
vignettes/basic_chunks.Rmd
Outdated
@@ -59,13 +59,8 @@ print(b) | |||
eval(expr_c) | |||
``` | |||
|
|||
A `chunk` object is an R6 object of class `chunk_call` which can be created and evaluated using the expressions above as follows: | |||
Now `chunk` objects can be created and evaluated using the expressions above as follows: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The chunk
objects can be created ...
It was always like that
vignettes/basic_chunks.Rmd
Outdated
As already said the chunks in the container will never throw an error upon execution. Errors are caught and stored in the `chunks` object. The most important function to check if everything went fine is `teal.code::chunks_is_ok`. It will return `TRUE` in the case where everything was fine. | ||
A chunks container object also has its own `eval` method. The function `teal.code::chunks_safe_eval` is merely a wrapper of this method. It is named `"safe_eval"` because it performs an additional step to handle errors by calling another method of the chunks container object, `validate_is_ok`. If any error occurs during the evaluation of expressions pushed into the chunks container, the error is handled and stored in the `chunk` object that contains the expression, and thus no error is thrown to the calling environment. | ||
|
||
The most important function to check if everything went fine is `teal.code::chunks_is_ok`. It will return `TRUE` in the case where everything was fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"everything went fine" what it means. we should be more explicit.
vignettes/basic_chunks.Rmd
Outdated
``` | ||
<img src="images/get_rcode.png" alt="get_rcode" style="width: 100%;"/> | ||
|
||
## Feature 4: `eval` - evaluating the code | ||
|
||
The `eval` function is responsible to run the code inside the chunks container. The `eval` function of a chunks container is called `teal.code::chunks_safe_eval`. It evaluates all chunks inside the container in the order they were pushed. It is not possible to change the order or run just pieces of the code. The chunks will not throw an error when being evaluated. See below for further details. | ||
The `eval` function is responsible to run the code inside the chunks container. The `eval` function of a chunks container is called `teal.code::chunks_safe_eval`. It evaluates all chunks inside the container in the order they were pushed. It is not possible to change the order or run just pieces of the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not clear, and conflict with the chapter 5
e.g. you use the function which is not yet introduced.
vignettes/basic_chunks.Rmd
Outdated
@@ -11,20 +11,20 @@ vignette: > | |||
|
|||
# The chunks container | |||
|
|||
The main concept behind the code chunks is the chunks container. This container consists of two elements: | |||
The main concept behind code reproducibility is the chunks container object. This object consists of two elements: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is too general now.
The main concept behind code reproducibility is the chunks container object. This object consists of two elements: | |
The main concept behind teal code reproducibility is the chunks container object. This object consists of two elements: |
The main concept behind code reproducibility is the chunks container object. This object consists of two elements: | |
The main concept behind code reproducibility is the chunks container object. This object consists of two elements: |
vignettes/basic_chunks.Rmd
Outdated
Normally as a module developer the chunks container will be used within the `server` function of a shiny/teal module. This enables storing the chunks container inside the shiny session. For simplicity reasons this feature will be used in the tutorial. To store a container inside the shiny session simply use the call `init_chunks()` and the `chunks` R6 object will be stored in `session$userData$<MODULENAME>$chunks`. After using `init_chunks()`, the functions dealing with chunks container can be used. Those are recommended. If for any reasons you want to use your own chunks container, it is possible. Please see the last section of this article for more information. So for now, we just call `teal.code::init_chunks()`. | ||
|
||
As a simulation of the teal environment the `init_session` function is provided: | ||
Normally as a module developer the chunks container will be used within the `server` function of a shiny/teal module. To create a chunks container object, call the R6 class `new` method: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is expected that the regular usage ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Contentwise vignette is fine. Just little details addressed by Maciej and highlighted in my suggestions. We should avoid using bquote
in the examples as 1-year ago we made a refactor of the modules to change bquote->substitute. We can mention several ways of making calls but we should focus on base::quote and base::substitute.
vignettes/basic_chunks.Rmd
Outdated
|
||
--- | ||
|
||
## Implementation of code chunks containers | ||
|
||
There are two ways to initialize the code chunks inside shiny modules: | ||
|
||
- Using R6 implementation: `session_chunks <- chunks$new()`. | ||
|
||
- Using `teal.code` wrappers: `teal.code::init_chunks()`. | ||
|
||
The `teal.code` functions can be used in both cases: | ||
|
||
|
||
```{r} | ||
session <- init_session() | ||
teal.code::init_chunks() | ||
a <- 1 | ||
b <- 2 | ||
|
||
# set a & b in env | ||
teal.code::chunks_reset() | ||
# push to chunks | ||
teal.code::chunks_push(expression = bquote(a <- a + 1)) | ||
# eval gives return value | ||
teal.code::chunks_safe_eval() | ||
stopifnot(teal.code::chunks_get_var("a") == 2) | ||
|
||
teal.code::chunks_push(expression = bquote(c <- a + b)) | ||
teal.code::chunks_safe_eval() | ||
stopifnot(teal.code::chunks_get_var("c") == 4) | ||
teal.code::chunks_push(expression = quote(a + b + c)) | ||
stopifnot(teal.code::chunks_safe_eval() == 8) | ||
# create a new chunks objet explicitly | ||
chunks2 <- teal.code::chunks$new() | ||
# push into this object | ||
teal.code::chunks_push(bquote(d <- 1), chunks = chunks2) | ||
# push the whole of chunks2 into our main chunks object | ||
teal.code::chunks_push_chunks(chunks2) | ||
# evaluate and get results | ||
teal.code::chunks_safe_eval() | ||
teal.code::chunks_get_var("d") | ||
``` | ||
|
||
The _default_ `chunks` object in many `teal.code` functions is the `chunks` object coupled to the shiny session. But as shown above it is possible to use other `chunk` objects with these functions using their `chunks` argument. The `chunks` object is an R6 object and consult the function documentation for details of its explicit methods. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this should be in advanced
vignettes/basic_chunks.Rmd
Outdated
|
||
The next sections will explain what a chunk is and how it is evaluated. | ||
|
||
# What is a chunk? | ||
|
||
A quoted R expression is a necessary step to create a **chunk** object. Quoted R expressions can be created in three different ways: | ||
A quoted R expression is a necessary step to create a **chunk** object, which is an R6 object of class `chunk_call`. Quoted R expressions can be created in three different ways: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to print the class and I think this markdown-chunk can be limited to this:
A quoted R expression is a necessary step to create a chunk object, which is an R6 object of class chunk_call
. Quoted R expressions can be created in several ways:
quote
when a call is composed as-is.substitute
when a call is composed basing on variables.- Alternatively, one can use
bquote
orrlang::expr
or any function which returns alanguage
(call
,expression
orname
).
# when call is composed as is
quote(a <- 2)
# when call is composed basing on values
substitute(x <- 2, list(x = as.name(a)))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the update.
closes #30
init_chunks