【问题标题】:Custom package throwing Invalid .internal.selfref detected data.table warning自定义包抛出 Invalid .internal.selfref detected data.table 警告
【发布时间】:2019-06-24 00:57:01
【问题描述】:

请参阅此Stackoverflow question 以获取有关此问题的背景信息。基于来自@jangorecki 的cmets,我对**exploit_url.R** 进行了以下更改,如下所示:'

#' @export
#' @import data.table
exploit_url <- function(df, href, target, anchor, new_col) {
  return(df[, (new_col) := paste0("<a href='", df[[href]], "' target='", target, "'>", df[[anchor]], "</a>", "<br>")][, c(1, 3:6, 8)])
}

按照第 1 步和第 2 步操作,NAMESPACEDESCRIPTION 中的所有内容都会得到处理。我收到一条警告消息,输出正确。

命名空间:

# Generated by roxygen2: do not edit by hand

import(data.table)

描述:

Package: poweR
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R: 
    person(given = "First",
           family = "Last",
           role = c("aut", "cre"),
           email = "first.last@example.com",
           comment = c(ORCID = "YOUR-ORCID-ID"))
Description: What the package does (one paragraph).
License: What license it uses
Encoding: UTF-8
LazyData: true
Imports: 
    data.table
RoxygenNote: 6.1.1.9000

输出:

新警告:

Warning message:
In `[.data.table`(df, , `:=`((new_col), paste0("<a href='", df[[href]],  :
  Invalid .internal.selfref detected and fixed by taking a (shallow) copy of the data.table so that := can add this new column by reference. At an earlier point, this data.table has been copied by R (or was created manually using structure() or similar). Avoid names<- and attr<- which in R currently (and oddly) may copy the whole data.table. Use set* syntax instead to avoid copying: ?set, ?setnames and ?setattr. If this message doesn't help, please report your use case to the data.table issue tracker so the root cause can be fixed or this message improved.

【问题讨论】:

    标签: r r-package


    【解决方案1】:

    阅读警告消息后,我意识到这可能与我创建 data.table 的方式有关。进一步的研究让我找到了这个Stackoverflow link,它帮助我理解了我做错了什么。

    我使用了以下代码:

    # Create dataframe for testing
    dput(head(cve_exploitdb[c(1:4),]))
    

    根据帖子,我们应该避免将 data.table 复制到列表中。出于好奇,我在原始 data.table 上运行了 package 函数,它没有任何警告消息

    【讨论】:

      猜你喜欢
      • 2013-12-05
      • 1970-01-01
      • 2013-06-12
      • 2014-09-12
      • 2020-06-02
      • 2014-01-08
      • 2013-04-09
      • 2017-08-24
      • 1970-01-01
      相关资源
      最近更新 更多