What does not run mean in R help pages?
"not run" encloses code that shouldn't be executed in the example
function (e.g. time-consuming code parts, user-interaction, ...).
see e.g. ?example
:
As detailed in the manual Writing R Extensions, the author of
the help page can markup parts of the examples for two exception
rules
'dontrun' encloses code that should not be run.
'dontshow' encloses code that is invisible on help pages, but will
be run both by the package checking tools, and the
'example()' function. This was previously 'testonly', and
that form is still accepted.
How to get help in R?
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
andfunction
."
?`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 vignette
s, 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"))
taskscheduleR runs ONCE but does not run HOURLY, WEEKLY, DAILY, etc
Use the startdate
argument indicating when this schedule should start working. The default of that is startdate = format(Sys.Date(), "%d/%m/%Y")
.
So I see you posted this on February 9. That would be 09/02/2018. But note that this depends on your locale. If you are in the US and you have a default locale, that means, start from the 2nd of September instead of the 9th of February.
If you are in Belgium, 09/02/2018 means, start on the 9th of February.
So change the startdate argument according to your locale, e.g. startdate = format(Sys.Date(), "%m/%d/%Y")
R: bench::mark does not return max and mean
It is usually useful to run
str(res)
to see what is the output of functions. In this case one of the object's members, near the end, is
# $ time :List of 1
# ..$ : 'bench_time' num 12.3ms 16.1ms 17.9ms 12.3ms 13.4ms ...
This means that res$time
is a list with just one member.
So the results are kept in res$time[[1]]
and the mean and maximum values can be calculated from it.
For instance, compare median(res$time[[1]])
with the printed result. They are the same value.
median(res$time[[1]])
#[1] 12.3ms
And the mean and maximum will be
mean(res$time[[1]])
#[1] 12.5ms
max(res$time[[1]])
#[1] 17.9ms
R documentation and help page - An example with the pipe operator
%>%
is an binary infix operator, you need to use it with operands, or you'll recieve an error. Hence the specified usage:
lhs %>% rhs
In you case above, writing ?%>%
will attempt to call %>%
using ?
as your lhs operator. Hence the error ... unexpected SPECIAL ...
. If you, on the other hand, wrap your operator in '...'
or "..."
, it will use the ?
prefix as you intend: showing the help section for that operator.
As an example, try the following in your console:
?< <-- Error: unexpected '<' in "?<"
?'<' <-- OK
?"<" <-- OK
(after first edit of question)
Now, regarding your updated question, where to find appropriate documentation for the pipe operator, I quote this site
Although not required, the tidyr and dplyr packages make use of the
pipe operator %>% developed by Stefan Milton Bache in the R package
magrittr. Although all the functions in tidyr and dplyr can be used
without the pipe operator, one of the great conveniences these
packages provide is the ability to string multiple functions together
by incorporating %>%.
Hence, an appropriate place to begin would be in the documentation for the magrittr
package:
- https://cran.r-project.org/web/packages/magrittr/vignettes/magrittr.html
- ...
?magrittr
or??magrittr
from your console.
(after second edit of question)
Finally, if we take a look at how the associated tidyr
manual page for the pipe operator is generated, we get our answer to your final edit:
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{\%>\%}
\alias{\%>\%}
\title{Pipe operator}
\usage{
lhs \%>\% rhs
}
\description{
See \code{\link[magrittr]{\%>\%}} for more details.
}
\keyword{internal}
Hence, your help page is supposed to contain a link to the magrittr
help page for the pipe operator, but if you are running from e.g. terminal (are you?), then you will only be shown plain text, in so loosing (or at least not seeing) the link.
what is the object type of mean in R?
What does ftype
tell us?
This function figures out whether the input function is a regular/primitive/internal function, a internal/S3/S4 generic, or a S3/S4/RC method. This is function is slightly simplified as it’s possible for a method from one class to be a generic for another class, but that seems like such a bad idea that hopefully no one has done it.
What does otype
give us?
Figure out which object system an object belongs to:
• base: no class attribute
• S3: class attribute, but not S4
• S4: isS4, but not RC
• RC: inherits from "refClass"
For reference:
pryr
package documentationR language objects
Related Topics
Reshape Multiple Categorical Variables to Binary Response Variables
How to Find the Indices of the Top 10,000 Elements in a Symmetric Matrix(12K X 12K) in R
Pie Charts in Ggplot2 with Variable Pie Sizes
The Simplest Way to Convert a List with Various Length Vectors to a Data.Frame in R
How to Group a Vector into a List of Vectors
How to Remove + (Plus Sign) from String in R
Keyed Lookup on Data.Table Without 'With'
Get First and Last Values Per Group - Dplyr Group_By with Last() and First()
Plotting During a Loop in Rstudio
Efficiently Merging Two Data Frames on a Non-Trivial Criteria
Converting Numeric Time to Datetime Posixct Format in R
How to Cumulatively Add Values in One Vector in R
Adjust Plot Title (Main) Position
Mutate with Case_When and Contains
Select Columns Based on Multiple Strings with Dplyr Contains()