This question already has an answer here:
How to access the help/documentation .rd source files in R?

(1 个回答)


1年前关闭。




我们如何获取现有函数的 R 文档源(*.Rd 的内容),比如 plotlubridate::ymd 。类似于 fix 的函数文档?

最佳答案

tools::Rd_db 为已安装的软件包创建已解析的 .Rd 文件的命名列表。例如,要打印 lubridate 的 .Rd 文件 ymd.Rd 的内容,您可以使用:

## create list of parsed .Rd files
db <- tools::Rd_db("lubridate")

## names of .Rd files
names(db)
#>  [1] "DateCoercion.Rd"      "DateTimeUpdate.Rd"    "Deprecated.Rd"
#>  [4] "Duration-class.Rd"    "Interval-class.Rd"    "Period-class.Rd"
#>  [7] "Timespan-class.Rd"    "am.Rd"                "as.duration.Rd"
#> [10] "as.interval.Rd"       "as.period.Rd"         "as_date.Rd"
#> [13] "date.Rd"              "date_decimal.Rd"      "day.Rd"
#> [16] "days_in_month.Rd"     "decimal_date.Rd"      "dst.Rd"
#> [19] "duration.Rd"          "fit_to_timeline.Rd"   "force_tz.Rd"
#> [22] "guess_formats.Rd"     "hidden_aliases.Rd"    "hms.Rd"
#> [25] "hour.Rd"              "interval.Rd"          "is.Date.Rd"
#> [28] "is.POSIXt.Rd"         "is.difftime.Rd"       "is.instant.Rd"
#> [31] "is.timespan.Rd"       "lakers.Rd"            "leap_year.Rd"
#> [34] "local_time.Rd"        "lubridate-package.Rd" "make_datetime.Rd"
#> [37] "make_difftime.Rd"     "minute.Rd"            "month.Rd"
#> [40] "mplus.Rd"             "now.Rd"               "origin.Rd"
#> [43] "parse_date_time.Rd"   "period.Rd"            "period_to_seconds.Rd"
#> [46] "pretty_dates.Rd"      "quarter.Rd"           "reclass_date.Rd"
#> [49] "reclass_timespan.Rd"  "rollback.Rd"          "round_date.Rd"
#> [52] "second.Rd"            "stamp.Rd"             "time_length.Rd"
#> [55] "timespan.Rd"          "today.Rd"             "tz.Rd"
#> [58] "week.Rd"              "with_tz.Rd"           "within-interval.Rd"
#> [61] "year.Rd"              "ymd.Rd"               "ymd_hms.Rd"

## print ymd.Rd
db[["ymd.Rd"]]
#> \title{Parse dates with \strong{y}ear, \strong{m}onth, and \strong{d}ay components}\name{ymd}\alias{ymd}\alias{ydm}\alias{mdy}\alias{myd}\alias{dmy}\alias{dym}\alias{yq}\keyword{chron}\description{
#> Transforms dates stored in character and numeric vectors to Date or POSIXct
#> objects (see \code{tz} argument). These functions recognize arbitrary
#> non-digit separators as well as no separator. As long as the order of
#> formats is correct, these functions will parse dates correctly even when the
#> input vectors contain differently formatted dates. See examples.
#> }\usage{
#> ymd(..., quiet = FALSE, tz = NULL, locale = Sys.getlocale("LC_TIME"),
#>   truncated = 0)
#>
#> ydm(..., quiet = FALSE, tz = NULL, locale = Sys.getlocale("LC_TIME"),
#>   truncated = 0)
#>
#> mdy(..., quiet = FALSE, tz = NULL, locale = Sys.getlocale("LC_TIME"),
#>   truncated = 0)
#>
#> myd(..., quiet = FALSE, tz = NULL, locale = Sys.getlocale("LC_TIME"),
#>   truncated = 0)
#>
#> dmy(..., quiet = FALSE, tz = NULL, locale = Sys.getlocale("LC_TIME"),
#>   truncated = 0)
#>
#> dym(..., quiet = FALSE, tz = NULL, locale = Sys.getlocale("LC_TIME"),
#>   truncated = 0)
#>
#> yq(..., quiet = FALSE, tz = NULL, locale = Sys.getlocale("LC_TIME"))
#> }
#> ... ETCETERA ...

关于r - 如何获取一个函数对应的Rd文档文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57647422/

10-12 18:00