想在 R 中打印环境中对象的属性

would like to print the properties of objects in environment in R

这种方法可行,但我想知道是否有更优雅的方法?

unlist(lapply(lapply(ls(), get), class))

你可以使用 mgetget 的倍数,然后使用 sapply 得到 class 来避免 unlist(lapply(...

sapply(mget(ls()), class)

有了purrr,我们可以做到

library(purrr)
mget(ls()) %>%
      map_chr(class)