如何在R中获得帮助? [英] How to get help in R?

查看:78
本文介绍了如何在R中获得帮助?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R包可能提供哪些文档?例如,我尝试了解sp包.

除了help(sp)之外,搜索帮助和文档还有哪些其他功能?

解决方案

获取有关您知道其名称的函数的帮助

使用 ? 或等效地 help .

?mean
help(mean) # same

对于非标准名称,请使用引号或反引号;参见 R简介:获得帮助具有功能和特色:

对于由特殊字符指定的功能,必须将参数用双引号或单引号引起来,使其成为字符字符串":对于一些具有语法含义的单词,包括ifforfunction."

?`if`
?"if"       # same
help("if")  # same

还有关于数据集,一般主题和某些软件包的帮助页面.

?iris
?Syntax
?lubridate    

使用 example 函数查看有关如何使用它.

example(paste)
example(`for`)

demo 函数提供了有关如何使用功能.

demo()                           # all demos in loaded pkgs
demo(package = .packages(all.available = TRUE)) # all demos
demo(plotmath)
demo(graphics)


找到您不知道其名称的函数

使用??或等效的 help.search .

??regression
help.search("regression")

同样,需要引用非标准的名称和短语.

??"logistic regression"

apropos 查找当前会话中的函数和变量匹配正则表达式的-space(但不在已安装但未加载的软件包中).

apropos("z$") # all fns ending with "z"

rseek.org 是具有 RSiteSearch 直接从R中搜索多个站点./p>

sos中的

findFn 包装RSiteSearch以HTML表格的形式返回结果.

RSiteSearch("logistic regression")

library(sos)
findFn("logistic regression")


查找程序包

available.packages 告诉您所有可在通过 setRepositories 设置的存储库中找到. installed.packages 告诉您已安装的所有软件包在 .libPaths 中指定的所有库中. library (无任何参数)相似,返回名称和已安装软件包的标语.

View(available.packages())
View(installed.packages())
library()
.libPaths()

类似地,没有参数的 data 会告诉您数据集在您的计算机上可用.

data()

search 告诉您已加载了哪些软件包.

search()

packageDescription 为您显示软件包DESCRIPTION文件.同样, news 读取NEWS文件.

packageDescription("utils")    
news(package = "ggplot2")


获取有关变量的帮助

ls 列出环境中的变量./p>

ls()                 # global environment
ls(all.names = TRUE) # including names beginning with '.'
ls("package:sp")     # everything for the sp package

大多数变量可以使用 str summary .

str(sleep)
summary(sleep)

ls.str 就像是lsstr.

ls.str()
ls.str("package:grDevices")
lsf.str("package:grDevices")  # only functions    

对于大变量(尤其是数据帧),请 head 函数对于显示前几行很有用.

head(sleep)

args 为您显示函数的参数.

args(read.csv)


关于R的一般知识

信息页面是一组非常全面的链接,用于链接免费的R资源.

R中的许多主题通过 vignette 记录,并以 browseVignettes 列出.

browseVignettes()
vignette("intro_sp", package = "sp")

通过将vignette edit 组合,可以在编辑器中获取其代码块.

edit(vignette("intro_sp",package="sp"))    

What is the possible documentation available for R package? For example I try to understand sp package.

In addition to help(sp), what are the other functions for searching through help and documentation?

解决方案

Getting help on a function that you know the name of

Use ? or, equivalently, help.

?mean
help(mean) # same

For non-standard names use quotes or backquotes; see An Introduction to R: Getting help with functions and features:

For a feature specified by special characters, the argument must be enclosed in double or single quotes, making it a "character string": This is also necessary for a few words with syntactic meaning including if, for and function."

?`if`
?"if"       # same
help("if")  # same

There are also help pages for datasets, general topics and some packages.

?iris
?Syntax
?lubridate    

Use the example function to see examples of how to use it.

example(paste)
example(`for`)

The demo function gives longer demonstrations of how to use a function.

demo()                           # all demos in loaded pkgs
demo(package = .packages(all.available = TRUE)) # all demos
demo(plotmath)
demo(graphics)


Finding a function that you don't know the name of

Use ?? or, equivalently, help.search.

??regression
help.search("regression")

Again, non-standard names and phrases need to be quoted.

??"logistic regression"

apropos finds functions and variables in the current session-space (but not in installed but not-loaded packages) that match a regular expression.

apropos("z$") # all fns ending with "z"

rseek.org is an R search engine with a Firefox plugin.

RSiteSearch searches several sites directly from R.

findFn in sos wraps RSiteSearch returning the results as a HTML table.

RSiteSearch("logistic regression")

library(sos)
findFn("logistic regression")


Finding packages

available.packages tells you all the packages that are available in the repositories that you set via setRepositories. installed.packages tells you all the packages that you have installed in all the libraries specified in .libPaths. library (without any arguments) is similar, returning the names and tag-line of installed packages.

View(available.packages())
View(installed.packages())
library()
.libPaths()

Similarly, data with no arguments tells you which datasets are available on your machine.

data()

search tells you which packages have been loaded.

search()

packageDescription shows you the contents of a package's DESCRIPTION file. Likewise news read the NEWS file.

packageDescription("utils")    
news(package = "ggplot2")


Getting help on variables

ls lists the variables in an environment.

ls()                 # global environment
ls(all.names = TRUE) # including names beginning with '.'
ls("package:sp")     # everything for the sp package

Most variables can be inspected using str or summary.

str(sleep)
summary(sleep)

ls.str is like a combination of ls and str.

ls.str()
ls.str("package:grDevices")
lsf.str("package:grDevices")  # only functions    

For large variables (particularly data frames), the head function is useful for displaying the first few rows.

head(sleep)

args shows you the arguments for a function.

args(read.csv)


General learning about R

The Info page is a very comprehensive set of links to free R resources.

Many topics in R are documented via vignettes, listed with browseVignettes.

browseVignettes()
vignette("intro_sp", package = "sp")

By combining vignette with edit, you can get its code chunks in an editor.

edit(vignette("intro_sp",package="sp"))    

这篇关于如何在R中获得帮助?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆