Simple question on access to individual input values

Hi All,

Apologies beforehand for the trivial question, but I am at a loss with the following way to access input values:

sapply(fields, function(x) input[[x]])

I do no understand why the following actually doesn't work:

sapply(fields, function(x) input$x)

The snippet comes from the first code example on https://shiny.rstudio.com/articles/persistent-data-storage.html.

Thanks in advance for your support !

Maybe the following will help clarify the difference between subsetting a list with and with [[. If [[ receives an unquoted value, it is interpreted as the name of a variable and the value of that variable is used as the element name. The takes the value passed to it as the name of the list element, whether or not is is quoted.

MyList <- list(A = 1:4, x = "Here is x")
x <- "A"
MyList[[x]]
#> [1] 1 2 3 4
MyList$x
#> [1] "Here is x"
MyList[["x"]]
#> [1] "Here is x"
MyList$"x"
#> [1] "Here is x"

Created on 2020-08-10 by the reprex package (v0.2.1)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.