0

I pass some parameters to this function (I make a reprex below) and works.

myReporter <- function(
  reports,
  data,
  ...
){
  blah
  blah
}

par <- list(
  Min = 202201,
  Max = 202204,
  closingmonth = 12
)

rpt <- do.call(
  myReporter,
  c(
    list(
      reports = reports,
      data = data
    ),
    par
  )
)

and works

But when I try to use reactive expressions, the dot-dot-dot does not work anymore. Inside myReporter function, the reactives' elements are still unevaluated, tought I put in their invocation parenthesis par() to force their evaluation before go inside.

par <- reactive({list(
  Min = input$min,
  Max = input$max,
  closingmonth = input$closingmonth
)})

rpt <- do.call(
  myReporter,
  c(
    list(
      reports = reports,
      data = data
    ),
    par()  #force evaluation
  )
)

MyReporter is not prepared to accept reactive expression, so I need to force their parameters to be evaluated before.

I left similar problem I guess in this Reprex

REPREX:

library(shiny)

ui <- fluidPage(
  numericInput("x1", "x1", value = 2),
  numericInput("x2", "x2", value = 2),
  numericInput("power_dotodotdot_1", "power_x1", value = 2),
  numericInput("power_dotodotdot_2", "power_x2", value = 2),
  verbatimTextOutput("res")
)

server <- function(input, output) {
  
  makeaverage <- function(x1, x2, ...){
    if(exists("power_x1")){x1 <- x1^power_x1}
    if(exists("power_x2")){x2 <- x2^power_x2}
    res <- (x1 + x2)/2
    return(res)
  }
  
  dots <- reactive(
    list(
      power_x1 = input$power_dotodotdot_1,
      power_x2 = input$power_dotodotdot_2
    )
  )
  
  output$res <- renderText({
    do.call(
      makeaverage,
      c(
        x1 = input$x1,
        x2 = input$x2,
      ),
      dots()
    )
  })
}

shinyApp(ui, server)

any ideas?

Captain Tyler
  • 500
  • 7
  • 19
  • 1
    Just like all reactive expressions, you can't just use the name to get the value -- you need to use `par()` to get the current value. The parenthesis are important. This doesn't seem at all specific to the use of `...` If that doesn't work, you'll really have to try harder to produce a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so we can actually run and test the code to see what's going on – MrFlick Jun 08 '22 at 20:54
  • do not work! `pars <- list(...) rpt <- do.call( myReporter, c( list( reports = reports, data = data ), pars() ) )` Error in pars() : could not find function "pars" – Captain Tyler Jun 08 '22 at 20:59
  • 1
    Your variable in the code above is `par` so it should be `par()`, not `pars()`. Was that just a typo? – MrFlick Jun 08 '22 at 21:12

0 Answers0