File: makeNamespace.R

package info (click to toggle)
r-cran-r.methodss3 1.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 300 kB
  • sloc: sh: 12; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 787 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
makeNamespace <- function(pkg = ".", style = c("minimal", "quoted")) {
  if (pkg == ".") {
    pathname <- file.path(pkg, "DESCRIPTION")
    if (!file_test("-f", pathname)) stop("No such file: ", sQuote(pathname))
    desc <- read.dcf(pathname)
    pkg <- desc[, "Package"]
    stopifnot(length(pkg) == 1L, !is.na(pkg))
  }
  style <- match.arg(style)
  ns <- getNamespace(pkg)
  for (name in ls(envir = ns, all.names = TRUE)) { 
    fcn <- get(name, envir = ns)
    if (!is.function(fcn)) next
    s3class <- attr(fcn, "S3class")
    if (is.null(s3class)) next
    name <- gsub(sprintf("[.]%s$", s3class), "", name)
    if (style == "minimal") {
      cat(sprintf('S3method(%s,%s)\n', name, s3class))
    } else {
      cat(sprintf('S3method("%s", "%s")\n', name, s3class))
    }
  }
}