确定R中的参数描述

时间:2014-02-08 23:18:45

标签: r arguments

我需要一种方法来确定R中参数的描述。

例如,如果我使用包ggplot2中的函数qplot(),我需要能够在qplot()中提取每个参数的描述。从ggplot2's reference manual开始,很容易看出有几个要考虑的论点。其中一个被称为“数据”,它被描述为:“要使用的数据帧(可选)。如果没有指定,将创建一个,从当前环境中提取向量。”

有没有办法从R会话中获取此信息,而不是通过阅读参考手册?也许一个类似于packageDescription()的R函数,但对于函数的参数?

谢谢!


编辑:我在这里回答了我的问题:

How to access the help/documentation .rd source files in R?

读取.Rd文件似乎是获取所需信息的最安全的方法。对于任何感兴趣的人,以下代码返回一个参数列表及其描述,其中“package_name”可以是您想要的任何包:

db <- Rd_db("package_name")
lapply(db, tools:::.Rd_get_metadata, "arguments")

感谢大家的帮助。

1 个答案:

答案 0 :(得分:0)

从Mac GUI R.app中的R控制台...当我查看help'seq', help_type="text")的文本输出(转到临时文件)时,我看到你想要的hte描述的开头是划分的由:

_A_r_g_u_m_e_n_t_s:   # Those underscores were ^H's before I pasted

然后参数出现在name:description对中:

     ...: arguments passed to or from methods.

from, to: the starting and (maximal) end values of the sequence.  Of
          length ‘1’ unless just ‘from’ is supplied as an unnamed
          argument.

      by: number: increment of the sequence.

length.out: desired length of the sequence.  A non-negative number,
          which for ‘seq’ and ‘seq.int’ will be rounded up if
          fractional.

along.with: take the length from the length of this argument.

当我使用终端会话获取相同的输出时,它出现在同一窗口中,但是作为Unix帮助页面,如:

Arguments:

     ...: arguments passed to or from methods.

from, to: the starting and (maximal) end values of the sequence.  Of
          length ‘1’ unless just ‘from’ is supplied as an unnamed
          argument.

      by: number: increment of the sequence.

length.out: desired length of the sequence.  A non-negative number,
          which for ‘seq’ and ‘seq.int’ will be rounded up if
          fractional.

along.with: take the length from the length of this argument.

我相信这些是由options("pager")的值调用的任何系统程序显示的。就我而言,那就是程序“少”。