【问题标题】:How do you find the lifecycle status of a tidyverse function or argument?如何找到 tidyverse 函数或参数的生命周期状态?
【发布时间】:2022-01-05 23:50:49
【问题描述】:

计算 tidyverse 函数的lifecycle stage 的正确方法是什么? (即函数/参数是否考虑stableexperimentaldeprecatedsuperseded

到目前为止我所知道的

文档会告诉我们,例如:library(tidyverse); ?summarise.groups 参数显示为“实验性”。

假设函数/参数是“稳定的”,除非它被明确指定为“实验性”、“不推荐”或“取代”正确,或者是否有更准确/更简单的方法来确定它是否“稳定” ?

背景

如果它是相关的,我试图解决的问题是一个朋友抱怨偶尔被弃用的 tidyverse 功能需要闪亮的应用程序维护。所以我想建议他们检查他们未来工作的“稳定”功能/参数,以尽量减少这种维护。就在他们这样做的最简单/最明智的方式之后。

【问题讨论】:

    标签: r tidyverse


    【解决方案1】:

    一个潜在的解决方案是使用 lifecycle package 中的 lint_tidyverse_lifecycle() function 对您的包/脚本进行 lint,以识别“不稳定”功能,例如

    (在 Rstudio 中):

    library(lifecycle)
    lint_tidyverse_lifecycle()
    

    就我而言,这给了我大量不稳定的功能,我需要更正/更新/修复:

    其中大部分都是非常简单的更改(即dplyr::sample_n() -> dplyr::slice_sample()),一旦所有问题都得到解决,脚本中使用的所有 tidyverse 函数都将“稳定”。

    【讨论】:

      【解决方案2】:

      有关调试代码,请参阅lint_lifecycle,它在文件中搜索匹配项。要找到函数的生命周期(这里专门针对 tidyverse),我们可以创建一个自定义函数。这些方法都没有在summarise 中识别像.groups 这样的实验参数。然后,它可能会导致以后令人沮丧的调试过程。对于这些功能,我会考虑找到一个稳定的替代方案,例如 base R aggregate

      f <- function(type = NULL){
        check_pkgs <- Vectorize(lifecycle:::pkg_lifecycle_statuses, "package")
        pkgs <- tidyverse::tidyverse_packages()
        l <- check_pkgs(pkgs)
        l <- l[lapply(l, length) > 0]
        df <- data.frame(pkg = unlist(l[seq.int(1, length(l), 3)], use.names = F),
                         fun = unlist(l[seq.int(2, length(l), 3)], use.names = F),
                         cycle = unlist(l[seq.int(3, length(l), 3)], use.names = F))
        if(!is.null(type)) subset(df, cycle == type) else df
      }
      
      # many functions are "experimental".
      f("experimental")
      

      对于非tidyverse函数,我们可以将pkgs &lt;- tidyverse_packages()替换为

      att <- .packages()
      pkgs <- att[!att %in% rownames(installed.packages(priority="base"))]
      

      如果情况需要,我们可以通过查找进行一些手动搜索

      needles <- f()$fun
      haystack <- rstudioapi::getActiveDocumentContext()[["contents"]]
      

      顺便说一句,tidyverse 文档中仍在使用更多阶段(lifecycle 不再推荐)。选项被取代、弃用、质疑、失效、实验性、软性弃用。进一步的警告是成熟退休

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-12-08
        • 2020-11-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-24
        相关资源
        最近更新 更多