Updating 'help_r.R' script
This commit is contained in:
parent
ccfb522e92
commit
50e3c80a95
|
@ -1,9 +1,7 @@
|
|||
* R_info
|
||||
|
||||
Some resources to learn about R
|
||||
|
||||
Some resources to learn about R.
|
||||
The R Project for Statistical Computing is a free environment for statistical computing and graphics.
|
||||
|
||||
More information about R: https://www.r-project.org/
|
||||
|
||||
** Index
|
||||
|
|
|
@ -39,12 +39,12 @@
|
|||
|
||||
* http://sillasgonzaga.com/material/curso_visualizacao/
|
||||
|
||||
** *Curso introdução à linguagem R para ecologia :pt:*
|
||||
** Curso introdução à linguagem R para ecologia :pt:
|
||||
|
||||
* Alexandre Adalardo de Oliveira
|
||||
* http://ecor.ib.usp.br/doku.php
|
||||
|
||||
** Blog curso sobre R e PostgreSQL
|
||||
** Blog curso sobre R e PostgreSQL :pt:
|
||||
|
||||
* Curso Consudata
|
||||
* http://rpg.consudata.com.br/
|
||||
|
|
|
@ -1,5 +1,16 @@
|
|||
* Resources to learn R within R
|
||||
|
||||
There are many sources to learn about R. As any GNU project, the manuals and info
|
||||
documentation are the first and most important source to be used.
|
||||
|
||||
Most of the times it is not necessary to open a question in a community nor open
|
||||
a browser to search in the web. Most of the times the answer is on your own
|
||||
copy of the manual.
|
||||
|
||||
R and all the packages have extensive documentation and there are also packages
|
||||
that can be used to learn R within R.
|
||||
|
||||
|
||||
** Package swirl
|
||||
|
||||
* https://swirlstats.com/
|
||||
|
@ -23,4 +34,36 @@ the name of the package as argument:
|
|||
vignette(package = "data.table")
|
||||
#+end_example
|
||||
|
||||
*** Find R documentation from emacs
|
||||
|
||||
If you use R in emacs, you can also the manuals can also be accessed using
|
||||
'info' program, typing:
|
||||
|
||||
: C-h i
|
||||
|
||||
Please note that "C" means "CTRL" key.
|
||||
|
||||
Then use 'ALT' + 'm' and write the initial words of the manual you are looking
|
||||
for:
|
||||
|
||||
: M m R
|
||||
|
||||
*** Find R documentation from a shell in GNU-linux systems
|
||||
|
||||
All the R manual can be accesed from a shell using the command "man":
|
||||
|
||||
#+begin_example sh
|
||||
man R
|
||||
#+end_example
|
||||
|
||||
Typing in terminal 'info -f' followed by the name of each section will display
|
||||
manual in "info" version:
|
||||
|
||||
* info -f R-intro
|
||||
* info -f R-data
|
||||
* info -f R-exts
|
||||
* info -f R-FAQ
|
||||
* info -f R-lang
|
||||
* info -f R-ints
|
||||
|
||||
Check the [[../script/help_r.R][script]] to see additional resources.
|
||||
|
|
103
script/help_r.R
103
script/help_r.R
|
@ -12,22 +12,33 @@
|
|||
#' highlight: zenburn
|
||||
#' ---
|
||||
|
||||
#' remove objects
|
||||
#' removing objects
|
||||
#'
|
||||
objects()
|
||||
|
||||
rm(list = ls())
|
||||
|
||||
#' Libraries
|
||||
|
||||
#' ## Common ways of getting help when working with R
|
||||
#'
|
||||
#' Within R use the "?" question symbol before any command and run
|
||||
|
||||
#' ## Find the formal arguments in a function
|
||||
#'
|
||||
formalArgs(help)
|
||||
|
||||
formalArgs(table)
|
||||
|
||||
#' ### Use "help", "help.search" or "find" when need to search for some terms
|
||||
#'
|
||||
#' Use "help.start" to view all R documentation
|
||||
help.start()
|
||||
|
||||
#' Within R use the "?" question symbol before any command and run the code
|
||||
#' to get help on that function.
|
||||
#'
|
||||
#' Getting help with "dput()" and "Compare" functions:
|
||||
#'
|
||||
?dput
|
||||
|
||||
#' Use "help", "help.search" or "apropos" when need search for some terms
|
||||
#'
|
||||
?Compare
|
||||
|
||||
#' Ask about control-flow constructs in R
|
||||
help("if")
|
||||
|
@ -38,22 +49,34 @@ help("[[")
|
|||
#' Help on "Quotes"
|
||||
help(Quotes)
|
||||
|
||||
#' Use "help.search" to find functions matching any word
|
||||
help.search("download file")
|
||||
|
||||
#' Find the formal arguments in a function
|
||||
formalArgs(help)
|
||||
|
||||
formalArgs(table)
|
||||
|
||||
#' "find" can be used to know which package contains a function
|
||||
#' ### "find" can be used to know which package contains a function
|
||||
|
||||
find("table")
|
||||
|
||||
find("count")#' this will return nothing, because the package should be loaded
|
||||
#' This will return nothing, because the package should be loaded in the session
|
||||
#' in order to "find" the function
|
||||
|
||||
find("count")
|
||||
|
||||
#' Then, after loading the package that contains the function it should run
|
||||
#' without any problem
|
||||
library(dplyr)
|
||||
|
||||
#' "apropos" give the name of objects containing the characters passed to the function
|
||||
find("count")
|
||||
|
||||
#' Unload a package from the environment
|
||||
#'
|
||||
detach("package:dplyr", unload = TRUE)
|
||||
|
||||
#' ### "apropos" gives the name of objects containing the characters passed to
|
||||
#' the function.
|
||||
#'
|
||||
#' Remember that wihin R (almost) everything that exist is an object and everything
|
||||
#' that happens is a function. Thus apropos will find any object (including
|
||||
#' functions) within the session matching the word.
|
||||
|
||||
count_testing <- c(1,2)
|
||||
|
||||
|
@ -61,35 +84,50 @@ apropos("count")
|
|||
|
||||
#' ## Examples and demostration of functions
|
||||
#'
|
||||
#' ### Examples included in packages documentation
|
||||
#'
|
||||
#' The function to show examples of any functions is called "example":
|
||||
example(glm)
|
||||
|
||||
library(lubridate)
|
||||
example(ymd)
|
||||
#' To extract examples of any function, the package containing the function should
|
||||
#' be loaded in the session:
|
||||
#'
|
||||
library(data.table)
|
||||
|
||||
example(Compare)
|
||||
#' Check some examples on how to use the function ".N" in the "data.table" package
|
||||
example(.N)
|
||||
|
||||
library(dplyr)
|
||||
example(case_when)
|
||||
|
||||
#' ### Using "demo()"
|
||||
demo(graphics)
|
||||
|
||||
#' Use "help.start" to view all R documentation
|
||||
help.start()
|
||||
|
||||
#' ## Searching in packages
|
||||
#'
|
||||
#' Obtain help in packages
|
||||
|
||||
library(help = data.table)
|
||||
|
||||
#' ## Finding objects within a package and checking documentation
|
||||
|
||||
#' Finding objects within a package
|
||||
|
||||
#' ### Finding objects
|
||||
#'
|
||||
#' Here we use "grep" to look for objects within the package "data.table".
|
||||
#' The function "search" is applied to look for R objects, thus the function
|
||||
#' will return the names of every function within the package
|
||||
#'
|
||||
library(data.table)
|
||||
|
||||
objects(grep("data.table", search()))
|
||||
|
||||
#' List vignettes in a package
|
||||
#' Take a look to the objects in the base package:
|
||||
#'
|
||||
obase <- objects(grep("base", search()))
|
||||
|
||||
head(obase, n=10)
|
||||
|
||||
#' ### List vignettes in a package
|
||||
|
||||
vignette(package = "data.table")
|
||||
|
||||
|
@ -97,17 +135,8 @@ browseVignettes("data.table")
|
|||
|
||||
vignette("datatable-faq")
|
||||
|
||||
#' Edit dataframe using R data editor
|
||||
#'
|
||||
|
||||
carros <- cars
|
||||
|
||||
fix(carros)
|
||||
|
||||
carros
|
||||
|
||||
#' Unload a package from the environment
|
||||
#'
|
||||
#' detach("package:data.table", unload = TRUE)
|
||||
|
||||
#' End
|
||||
|
||||
#' You can export this document as html using "rmarkdown":
|
||||
#'
|
||||
#' rmarkdown::render("./help_r.R")
|
||||
|
|
Loading…
Reference in New Issue