Explore Courses Blog Tutorials Interview Questions
0 votes
in R Programming by (50.2k points)

The below code is a part of a Shiny app and that app is having a function f(x1):

y <- lapply(input$A, FUN = f)

I know that I need to add a second argument, making it f(x1, x2), where x2 is a different input. But the below code is giving me an error that I am using ... incorrectly

y <- lapply(input$A, FUN = f(..., input$B))

Can someone guide me what is the proper syntax?

1 Answer

0 votes
by (108k points)

If you are having multiple arguments then, we can use Map/mapply:

Map(f, input$A, input$B)

If you wish to use lapply then, an option is to loop over the sequence of input$A

lapply(seq_along(input$A), function(i) f(input$A[i], input$B[i]))

Or with purrr:


map2(input$A, input$B, f)

If you are a beginner and want to know more about R then do check out the R programming tutorial

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

29.3k questions

30.6k answers


104k users

Browse Categories