#' --- #' title: "Getting help in R" #' date: "2021-11-24" #' author: "Jose" #' output: #' html_document: #' code_folding: show #' toc: yes #' toc_float: #' smooth_scroll: true #' df_print: paged #' highlight: zenburn #' --- #' removing objects #' rm(list = ls()) #' ## Common ways of getting help when working with R #' #' ## 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 ?Compare #' Ask about control-flow constructs in R help("if") #' Information about extract or replace function help("[[") #' Help on "Quotes" help(Quotes) #' Use "help.search" to find functions matching any word help.search("download file") #' ### "find" can be used to know which package contains a function find("table") #' 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) 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) 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) #' To extract examples of any function, the package containing the function should #' be loaded in the session: #' library(data.table) #' 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) #' ## Searching in packages #' #' Obtain help in packages library(help = data.table) #' ## Finding objects within a package and checking documentation #' ### 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())) #' 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") browseVignettes("data.table") vignette("datatable-faq") #' End #' You can export this document as html using "rmarkdown": #' #' rmarkdown::render("./help_r.R")