-
Notifications
You must be signed in to change notification settings - Fork 3
Call capture.output() instead of getSrcref() to read design code #61
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
Conversation
This generates the same output for code attribute as before, but does not depend on `keep_source` during package install to work. Shinyapps.io also doesn't seem to support options when building dependencies, so moving away from getSrcref() allows shinyapps to install and run designer functions without issues.
|
Capture.output relies on print, see deparse instead
…On Wed, May 23, 2018, 7:40 AM Clara Bicalho ***@***.***> wrote:
This addresses #50
<#50> by generating
the same output for designer code attribute as before, except it does not
depend on keep_source during package install to work.
Shinyapps.io also doesn't seem to support options when building
dependencies, so moving away from getSrcref() allows shiny.io server to
install and run designer function calls without issues (currently app
outputs relying on design call are returning errors).
------------------------------
You can view, comment on, or merge this pull request online at:
#61
Commit Summary
- Call capture.output() instead of getSrcref() to read design code
File Changes
- *M* R/helpers.R
<https://github.com/DeclareDesign/DesignLibrary/pull/61/files#diff-0>
(2)
Patch Links:
- https://github.com/DeclareDesign/DesignLibrary/pull/61.patch
- https://github.com/DeclareDesign/DesignLibrary/pull/61.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#61>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AAZjTshjToxXIEV4VP1ZPDyW9oAHbs8tks5t1XT0gaJpZM4UKlur>
.
|
Pull Request Test Coverage Report for Build 242
💛 - Coveralls |
|
This is exciting, thanks. I could see an argument for staying with test <- function(){
"don't grab this code"
{{{
"grab this code"
}}}
return()
}
txt_deparse <- deparse(test)
txt_capture <- capture.output(test)
# This breaks due to line-splitting
grep("[{]{3}", txt_deparse)
# This does not break
grep("[{]{3}", txt_capture)However, both break here so we need to solve the line-splitting problem: |
|
capture.output calls the print.function method implicitly, which uses the
getsrcref if its' there and deparse if it isn't - see
https://github.com/wch/r-source/blob/fe7d9b54b2f56fcae876603617aebc668fef68cc/src/main/print.c#L184
You should choose one and stick to it, otherwise the output could depend on
the environment (eg some users see the comments in the design and some
don't)
…On Wed, May 23, 2018 at 8:13 AM, Jasper Cooper ***@***.***> wrote:
This is exciting, thanks.
I could see an argument for staying with capture.output() over deparse():
test <- function(){
"don't grab this code"
{{{
"grab this code"
}}}
return()
}
txt_deparse <- deparse(test)txt_capture <- capture.output(test)
# This breaks due to line-splitting
grep("[{]{3}", txt_deparse)# This does not break
grep("[{]{3}", txt_capture)
However, both break here so we need to solve the line-splitting problem:
test <- function() {
"don't grab this code"
{
{
{
"grab this code"
}
}
}
return()
}
txt_deparse <- deparse(test)
txt_capture <- capture.output(test)
grep("[{]{3}", txt_deparse)
grep("[{]{3}", txt_capture)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#61 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAZjTjT9C5BtTKDwJ7aBpYLup-WZu3IRks5t1XymgaJpZM4UKlur>
.
|
|
Another alternative is to revert from the getSrcRef version to the original
version of the helper function, which unpacked the function body
programatically - comments won't be available though, which was why it was
changed.
…On Wed, May 23, 2018 at 8:18 AM, Neal Fultz ***@***.***> wrote:
capture.output calls the print.function method implicitly, which uses the
getsrcref if its' there and deparse if it isn't - see
https://github.com/wch/r-source/blob/fe7d9b54b2f56fcae876603617aebc
668fef68cc/src/main/print.c#L184
You should choose one and stick to it, otherwise the output could depend
on the environment (eg some users see the comments in the design and some
don't)
On Wed, May 23, 2018 at 8:13 AM, Jasper Cooper ***@***.***>
wrote:
> This is exciting, thanks.
>
> I could see an argument for staying with capture.output() over deparse():
>
> test <- function(){
> "don't grab this code"
> {{{
> "grab this code"
> }}}
> return()
> }
> txt_deparse <- deparse(test)txt_capture <- capture.output(test)
> # This breaks due to line-splitting
> grep("[{]{3}", txt_deparse)# This does not break
> grep("[{]{3}", txt_capture)
>
> However, both break here so we need to solve the line-splitting problem:
>
> test <- function() {
> "don't grab this code"
> {
> {
> {
> "grab this code"
> }
> }
> }
> return()
> }
>
> txt_deparse <- deparse(test)
> txt_capture <- capture.output(test)
>
> grep("[{]{3}", txt_deparse)
> grep("[{]{3}", txt_capture)
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#61 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAZjTjT9C5BtTKDwJ7aBpYLup-WZu3IRks5t1XymgaJpZM4UKlur>
> .
>
|
|
Awesome, thanks so much for that clarification Neal. I see your point about the environment. Any drawbacks to using |
|
internally, each function body is stored as an expression tree object -
`deparse` converts that back to text - that means comments and whitespace
can change. The reason why each `{` gets its own line with deparse is that
each one is a separate node in the expression tree, and R prints a new line
for each one.
…On Wed, May 23, 2018 at 8:27 AM, Jasper Cooper ***@***.***> wrote:
Awesome, thanks so much for that clarification Neal. I see your point
about the environment.
Any drawbacks to using deparse(), aside from the splitting (which is easy
enough to work around)? It's not using the source code at all?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#61 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAZjTqV2shdHWRkG28wQ3QmTHsYJPm60ks5t1X_hgaJpZM4UKlur>
.
|
|
OK that makes sense and also explains the comment issue. I hadn't noticed deparse() was ignoring comments. So either:
Edit: I tested building the package using capture.output() and not keeping source, and it doesn't work. |
|
For behavior of number 3, strongly recommend writing your own helper
instead of relying on `capture.output(print(design_template))` - print is
generic and can be overrode, for example if people have crayon / colorout
loaded there can be control codes for color or other garbage in the output.
We should check if the srcref attribute is present, if so use it, otherwise
fall back to deparse.
…On Wed, May 23, 2018 at 9:27 AM, Jasper Cooper ***@***.***> wrote:
OK that makes sense and also explains the comment issue. I hadn't noticed
deparse() was ignoring comments.
So either:
1. we rely on source code and have comments, at the cost of lots of
install problems
2. we use an expression tree approach, but lose comments because
they're not part of the tree
3. we rely on capture.output which will not have comments when it
doesn't have the source, but should otherwise work OK, with the possible
issue of changes to the environment
If I've accurately summarized the choices we face, I'd vote for 3 I think
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#61 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAZjTrbqsfMAVdZIgO5ra_RBTujABCh2ks5t1Y32gaJpZM4UKlur>
.
|
|
I use |
More accurate indexing (only takes lines of code with whitespace and curly braces. Fixes break with regression_discontinuity_designer().
|
OK I'm currently running some tests of the keep.source and not keep.source versions of the build. I'm a little bit sad we have lost comments using deparse. |
- at the moment it is running in both builds (with source and without)
|
If you are falling back to deparse, you should locate the {{{ block in the expression tree directly instead of using a regex, like in the original version of this function. |
|
Also on shinyapps.io, did you try setting the R_KEEP_PKG_SOURCE in Renviron or Renviron.site? It might get picked up that way- https://stackoverflow.com/questions/39084284/how-to-pass-environment-variables-to-shinyapps |
|
On shinyapps.io question: yes, I tried that and did not work. Is
setting R_KEEP_PKG_SOURCE=yes
in .Renviron enough on a Windows computer? It seems like ?Startup suggests
a different default directory for .Renviron and .Rprofile, but perhaps I'm
misreading it:
"On systems with sub-architectures (mainly Windows), the files
‘Renviron.site’ and ‘Rprofile.site’ are looked for first in
architecture-specific directories, e.g. ‘R_HOME/etc/i386/Renviron.site’.
And e.g. ‘.Renviron.i386’ will be used in preference to ‘.Renviron’."
Thanks for pointing to find_triple_bracket(), very helpful and much neater
than regex.
2018-05-25 0:00 GMT+02:00 Neal Fultz <notifications@github.com>:
… Also on shinyapps.io, did you try setting the R_KEEP_PKG_SOURCE in
Renviron or Renviron.site? It might get picked up that way-
https://stackoverflow.com/questions/39084284/how-to-
pass-environment-variables-to-shinyapps
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#61 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AYa0JBIwCwADVj9lT8udjTogTprxK4L4ks5t1y2EgaJpZM4UKlur>
.
|
|
I would recommend opening a support ticket for shinyapps and see if they have a way of getting the env vars set at install time instead of just run time. |
Cleans `{{{` using expression rather than regex on string.
|
OK I'm going to merge this but have to fix some of the tests that have been broken with updates to diagnose_design |
jaspercooper
left a comment
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.
All looks good
R/helpers.R
Outdated
| close <- grep("[}]{3}", txt) | ||
| if(length(txt)==0){ | ||
| txt <- deparse(designer) | ||
| x <- grep("^[[:blank:]]*[{]", txt) |
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.
Can we name x something more informative and also add some comments explaining what is happening at each step here?
R/helpers.R
Outdated
| txt <- deparse(designer) | ||
| x <- grep("^[[:blank:]]*[{]", txt) | ||
| open <- x[which(diff(x) == 1)] | ||
| if(length(open)>3) stop("More than three consecutive `{` found in ", substitute(designer)) |
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.
Is this necessarily a problem to have more than 3? totally fine to leave it in there, but a priori I can't see the problem in including anything between the last three braces in {{{{{ and the first three braces in }}}}}.
|
OK this is ready to go |
This addresses #50 by generating the same output for designer code attribute as before, except it does not depend on
keep_sourceduring package install to work.Shinyapps.io also doesn't seem to support options when building dependencies, so moving away from getSrcref() allows shiny.io server to install and run designer function calls without issues (currently app outputs relying on design call are returning errors).