JS работает правильно в Codepen, но не визуальный код студии

В первом примере вы можете просто сделать:

lapply(dflist, `$.data.frame`, "a")

Для второго используйте функцию доступа slot()

lapply(mylist, "slot", "tab")

Я не уверен , почему отправка метода не работает в первом случае, но раздел Note в ?lapply действительно затрагивает эту самую проблему его отправки borked методом для примитивных функций, таких как $:

 Note:

 [...]

 For historical reasons, the calls created by ‘lapply’ are
 unevaluated, and code has been written (e.g., ‘bquote’) that
 relies on this.  This means that the recorded call is always of
 the form ‘FUN(X[[i]], ...)’, with ‘i’ replaced by the current
 (integer or double) index.  This is not normally a problem, but it
 can be if ‘FUN’ uses ‘sys.call’ or ‘match.call’ or if it is a
 primitive function that makes use of the call.  This means that it
 is often safer to call primitive functions with a wrapper, so that
 e.g. ‘lapply(ll, function(x) is.numeric(x))’ is required to ensure
 that method dispatch for ‘is.numeric’ occurs correctly.
-1
задан Kellz 16 January 2019 в 16:04
поделиться