Skip to content

Conversation

@clarabicalho
Copy link
Contributor

This addresses #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).

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.
@clarabicalho clarabicalho requested a review from jaspercooper May 23, 2018 14:40
@nfultz
Copy link
Contributor

nfultz commented May 23, 2018 via email

@coveralls
Copy link

coveralls commented May 23, 2018

Pull Request Test Coverage Report for Build 242

  • 8 of 18 (44.44%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-2.4%) to 94.03%

Changes Missing Coverage Covered Lines Changed/Added Lines %
R/helpers.R 8 18 44.44%
Files with Coverage Reduction New Missed Lines %
R/helpers.R 1 61.76%
Totals Coverage Status
Change from base Build 240: -2.4%
Covered Lines: 378
Relevant Lines: 402

💛 - Coveralls

@jaspercooper
Copy link
Contributor

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)

@nfultz
Copy link
Contributor

nfultz commented May 23, 2018 via email

@nfultz
Copy link
Contributor

nfultz commented May 23, 2018 via email

@jaspercooper
Copy link
Contributor

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?

@nfultz
Copy link
Contributor

nfultz commented May 23, 2018 via email

@jaspercooper
Copy link
Contributor

jaspercooper commented May 23, 2018

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

Edit: I tested building the package using capture.output() and not keeping source, and it doesn't work.

@nfultz
Copy link
Contributor

nfultz commented May 23, 2018 via email

@clarabicalho
Copy link
Contributor Author

I use getSrcref() and deparse() if source file is not available. Built from this branch and ran fine. I don't see the advantage of having it both ways over using deparse() in all cases though.

More accurate indexing (only takes lines of code with whitespace and curly braces. Fixes break with regression_discontinuity_designer().
@jaspercooper
Copy link
Contributor

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

nfultz commented May 24, 2018

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.

f <- function(x){
  {FALSE}
  {{{
    step1 <- a
    step2 <- b
    step3 <- c
    step4 <- z
    design <- step1 / step2 / step3 / step4
    
  }}}
  {{FALSE}}
  {FALSE}
  x
}


find_triple_bracket <- function(f){
  
  pred <- function(expr, depth=3) {
    (depth == 0) || (
      length(expr) > 1 &&
        expr[[1]] == as.symbol('{') &&
        Recall(expr[[2]], depth - 1)
    )
  }
  
  clean <- function(ch, n=length(ch)-1) paste0(ch[2:n], collapse = "\n")
  
  ret <- Filter(pred, body(f))
  
  if(length(ret) == 0) "" else clean(deparse(ret[[1]][[2]][[2]]))
  
}

find_triple_bracket(f)

@nfultz
Copy link
Contributor

nfultz commented May 24, 2018

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

@clarabicalho
Copy link
Contributor Author

clarabicalho commented May 25, 2018 via email

@nfultz
Copy link
Contributor

nfultz commented May 25, 2018

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

OK I'm going to merge this but have to fix some of the tests that have been broken with updates to diagnose_design

Copy link
Contributor

@jaspercooper jaspercooper left a 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)
Copy link
Contributor

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

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

@jaspercooper
Copy link
Contributor

OK this is ready to go

@jaspercooper jaspercooper merged commit 36eaf66 into master Jun 4, 2018
@jaspercooper jaspercooper deleted the get_design_code branch June 14, 2018 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants