从嵌套列表

时间:2017-03-24 20:38:55

标签: r list function organization r-package

在嵌套R内组织我的functions lists然后在包的不同部分调用它们是否很昂贵?例如,假设我有以下伪代码:

ThetaEstimates <- list(

    # different approaches to estimate WLE
    collection.wle = list(
        via.package.x = function(...) {
            stop("not implemented")
        },

        via.package.y = function(...) {
            stop("not implemented")
        },

        via.cpp = function(...) {
            stop("not implemented")
        }
    ),


    # different approaches to estimate WL
    collection.wl = list(
        # same as above
    ),


    # different approaches to estimate EAP
    collection.eap = list(
        # same as above
    )

) # ThetaEstimates

然后,我想在导出的functions内或R6Class initialize()内调用这些函数,如:

Estimator = R6::R6Class("Estimator",
    # public
    public = list(
        initialize = function(method) {
            if (methods == "WLE") {
                ThetaEstimates$collection.wle$via.mirt()
            } else if(...) {
                # and so on
            } else {
                # and so on
            }
        }
    )
) # Estimator

我一直在四处寻找,但我找不到关于这个话题的自以为是的答案。通过浏览GitHub上的不同存储库,我发现大多数人都希望在functions个文件中使用utils.R,所有文件都位于同一位置。但是,我担心随着越来越多的functions被添加,这可能很难处理。具体来说,我的问题是:

  • 从嵌套functions组织和调用lists是否存在性能瓶颈?
  • 要了解如何更好地组织R包裹,需要咨询哪些好的资源或存储库?

我希望这个问题不要太模糊或广泛(如果需要,我会添加更多细节)。提前谢谢。

0 个答案:

没有答案
相关问题