Skip to content
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

Merged
merged 6 commits into from
May 16, 2022
Merged

Conversation

denisovan31415
Copy link
Contributor

closes #30

  • removed all mentions of init_chunks
  • tidy up wording

@github-actions
Copy link
Contributor

github-actions bot commented May 12, 2022

Code Coverage Summary

Filename                Stmts    Miss  Cover    Missing
--------------------  -------  ------  -------  ----------------------------------------------------------------------------------------------------------------------------------------
R/chunk.R                 150       3  98.00%   363-369
R/chunks_pipe.R            28      25  10.71%   16-48
R/chunks.R                402      40  90.05%   334, 424, 430-433, 439, 466-467, 484-491, 500, 506-515, 561, 587, 593-594, 596, 612, 621, 630, 672, 675, 698-703, 1029, 1050, 1104, 1155
R/get_eval_details.R      113     113  0.00%    15-178
R/include_css_js.R          7       7  0.00%    12-19
R/utils.R                  24      19  20.83%   13, 17-38
TOTAL                     724     207  71.41%

Results for commit: e972667

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@github-actions
Copy link
Contributor

github-actions bot commented May 12, 2022

Unit Tests Summary

    1 files      3 suites   3s ⏱️
  42 tests   42 ✔️ 0 💤 0
294 runs  294 ✔️ 0 💤 0

Results for commit 397f05f.

♻️ This comment has been updated with latest results.

@Polkas Polkas self-assigned this May 13, 2022
Polkas
Polkas previously requested changes May 13, 2022
Copy link
Contributor

@Polkas Polkas left a 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 Polkas dismissed their stale review May 13, 2022 08:20

I will start from scratch

@gogonzo
Copy link
Contributor

gogonzo commented May 13, 2022

@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 might be big new user of our chunks and should we encurange them to use init_chunks? I don't think so

Copy link
Contributor

@Polkas Polkas left a 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.


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:
Copy link
Contributor

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

Copy link
Contributor

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 or rlang::expr or any function which returns a language (call, expression or name).
# when call is composed as is
quote(a <- 2)

# when call is composed basing on values
substitute(x <- 2, list(x = as.name(a)))

@@ -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:
Copy link
Contributor

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

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.
Copy link
Contributor

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.

```
<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.
Copy link
Contributor

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.

@@ -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:
Copy link
Contributor

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.

Suggested change
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:
Suggested change
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:

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:
Copy link
Contributor

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 ..

Copy link
Contributor

@gogonzo gogonzo left a 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.

Comment on lines 201 to 283

---

## 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.
Copy link
Contributor

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


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:
Copy link
Contributor

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 or rlang::expr or any function which returns a language (call, expression or name).
# when call is composed as is
quote(a <- 2)

# when call is composed basing on values
substitute(x <- 2, list(x = as.name(a)))

@denisovan31415
Copy link
Contributor Author

@Polkas @gogonzo

I think I have address all of your comments.

In addition, I removed the gif summary at the end because it is now outdated and it was difficult to follow.

Copy link
Contributor

@Polkas Polkas left a 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.

@denisovan31415 denisovan31415 merged commit be0f5ea into main May 16, 2022
@denisovan31415 denisovan31415 deleted the 30_remove_init_chunks_doc@main branch May 16, 2022 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

removed init_chunks from basic chunks vignette
3 participants