使用data.table自定义函数创建自定义R包

时间:2019-06-23 02:05:01

标签: r r-package

我想按照以下非常简单明了的说明创建一个软件包,https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/但是,以下函数不在软件包内部时起作用,而在软件包中则不起作用。

要重现此内容,请在默认文件夹中运行以下命令:步骤1

library("devtools")
library(roxygen2)
create_package("poweR")

这将带您进入新窗口,并在该窗口中:第2步

exploit_url.R:创建并复制到软件包的R文件夹

#' @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)])
}

然后在将文件创建并复制/保存到软件包的R文件夹后运行以下命令:

library(devtools)
use_package("data.table")
document()
build()
install()

关闭该窗口,然后返回到步骤1

library("poweR")
library(data.table)
DT <- structure(list(cveid = c("CVE-2008-4726", "CVE-2018-18798", "CVE-2001-0791", 
                             "CVE-2005-1823"), EDB_ID = c("6804", "45727", "20893", "25766"
                             ), Type = c("remote", "webapps", "remote", "webapps"), 
                   Platform = c("Windows","PHP", "Windows", "PHP"), 
                   E_DB_Verified = c("Verified", "Waiting verification", "Verified", "Verified"), 
                   E_DB_Published = c("2008-10-22", "2018-10-29", "2001-05-24", "2005-05-30"), 
                   url = c("https://www.exploit-db.com/exploits/6804/","https://www.exploit-db.com/exploits/45727/", 
                           "https://www.exploit-db.com/exploits/20893/", "https://www.exploit-db.com/exploits/25766/")), 
                   class = c("data.table", "data.frame"), row.names = c(NA, -4L))


DT <- exploit_url(DT, "url", '_blank', "E_DB_Verified", "exploitdburl")

我收到以下错误:

Error in exploit_url(DT, "url", "_blank", "E_DB_Verified", "exploitdburl") : 
  could not find function "exploit_url" 

我缺少什么吗?任何建议都将受到欢迎

1 个答案:

答案 0 :(得分:1)

根据const http = require('http'); const server = http.createServer((req, res) => { console.log('url', req.url); res.setHeader('Content-Type', 'text/html'); res.end('<h1>Hellooooooooooooooo</h1>'); }); server.listen(3000); 的评论解决了该问题。