Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

r faq - How to get help in R?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"))    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...