Reputation: 246
I wanted to create a package following these very clear and simple instructions, https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/ However the following function works when it is not inside a package, but does not work when in a package.
To reproduce this, run the following command in your default folder:Step 1
library("devtools")
library(roxygen2)
create_package("poweR")
This will take you to a new window and in that window: Step 2
exploit_url.R: Create and Copy this to R folder of package
#' @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)])
}
Then run the following commands after creating and copying/saving file to R folder of package:
library(devtools)
use_package("data.table")
document()
build()
install()
Close that window and go back to window Step 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")
I get the following error:
Error in exploit_url(DT, "url", "_blank", "E_DB_Verified", "exploitdburl") :
could not find function "exploit_url"
Is there something I am missing? Any suggestions will be welcome
Upvotes: 1
Views: 275