我用感兴趣的包中的函数名称创建了一个数据框。
# loading needed libraries
library(ggstatsplot)
library(tidyverse)
# creating a dataframe with namespace from package of interest
(
df_ns <- getNamespaceExports(ns = "ggstatsplot") %>%
tibble::as_data_frame(.) %>%
dplyr::filter(.data = ., grepl("^gg|^grouped", value)) %>%
dplyr::filter(.data = ., value != "ggcoefstats") %>%
dplyr::mutate(
.data = .,
functions = paste("ggstatsplot::", value, sep = "")
) %>%
dplyr::mutate(
.data = .,
version = dplyr::case_when(grepl("^grouped", value) ~ "grouped",
TRUE ~ "basic")
) %>%
dplyr::mutate(
.data = .,
value = stringr::str_remove(value, "grouped_")
) %>%
dplyr::arrange(.data = ., value)
)
#> # A tibble: 10 x 3
#> value functions version
#> <chr> <chr> <chr>
#> 1 ggbetweenstats ggstatsplot::grouped_ggbetweenstats grouped
#> 2 ggbetweenstats ggstatsplot::ggbetweenstats basic
#> 3 ggcorrmat ggstatsplot::grouped_ggcorrmat grouped
#> 4 ggcorrmat ggstatsplot::ggcorrmat basic
#> 5 gghistostats ggstatsplot::grouped_gghistostats grouped
#> 6 gghistostats ggstatsplot::gghistostats basic
#> 7 ggpiestats ggstatsplot::grouped_ggpiestats grouped
#> 8 ggpiestats ggstatsplot::ggpiestats basic
#> 9 ggscatterstats ggstatsplot::grouped_ggscatterstats grouped
#> 10 ggscatterstats ggstatsplot::ggscatterstats basic
现在我想要的是一列,其中包含functions
列中每个函数的参数数量。可以通过以下方式对个人函数进行此操作:
# example
length(formals(ggstatsplot::ggbetweenstats))
#> [1] 42
但是我想对functions
列中包含的所有功能执行此操作,并创建一个包含参数计数的新列n
。但是函数没有得到正确的评估,并且我得到了所有函数的0
自变量计数。我该如何解决这个问题?
# extracting argument count for all functions
purrrlyr::by_row(
.d = df_ns,
..f = ~ length(formals(rlang::parse_expr(.$functions))),
.collate = "cols",
.to = "n"
)
#> Warning in formals(fun): argument is not a function
#> Warning in formals(fun): argument is not a function
#> Warning in formals(fun): argument is not a function
#> Warning in formals(fun): argument is not a function
#> Warning in formals(fun): argument is not a function
#> Warning in formals(fun): argument is not a function
#> Warning in formals(fun): argument is not a function
#> Warning in formals(fun): argument is not a function
#> Warning in formals(fun): argument is not a function
#> Warning in formals(fun): argument is not a function
#> # tibble [10 x 4]
#> value functions version n
#> <chr> <chr> <chr> <int>
#> 1 ggbetweenstats ggstatsplot::grouped_ggbetweenstats grouped 0
#> 2 ggbetweenstats ggstatsplot::ggbetweenstats basic 0
#> 3 ggcorrmat ggstatsplot::grouped_ggcorrmat grouped 0
#> 4 ggcorrmat ggstatsplot::ggcorrmat basic 0
#> 5 gghistostats ggstatsplot::grouped_gghistostats grouped 0
#> 6 gghistostats ggstatsplot::gghistostats basic 0
#> 7 ggpiestats ggstatsplot::grouped_ggpiestats grouped 0
#> 8 ggpiestats ggstatsplot::ggpiestats basic 0
#> 9 ggscatterstats ggstatsplot::grouped_ggscatterstats grouped 0
#> 10 ggscatterstats ggstatsplot::ggscatterstats basic 0
由reprex package(v0.2.1)于2018-10-11创建