Chapter 2 R Language
2.1 Is there a way to obtain source code of non-exported function
2.2 Packages
2.2.1 sf
- All the functions have the prefix
st
which means spatial and temporal.
2.2.2 Markdown
Rstudio has some particular templates for Markdown. When using knit
it is not able
to render adequately the markdown file. Then is better to use:
rmarkdown::render("my-file.Rmd")
2.2.3 Bookdown
git clone
- One chapter lives in ones R Markdown file
01-intro.Rmd
or01-intro.Rmd
. index.Rmd
is the first file as usual in webpages._example.Rmd
is skipped.
2.4 Math labels
use expression
with paste
, bquote
, and math notation
2.5 Sf and ggplot
geom_sf
:
- Use
fill = NA
when you want fill color. - By default, it uses datum
4326
. You can change it usingcoord_sf
. For example, you can setcoord_sf(datam = 3857)
.
2.6 Rmd and knitr
knitr::opts_chunk$set(eval = FALSE)
to not evaluate any R code.
2.7 Regular expresion
Lookahead assertion to find expressions that does not match. For example, all strings that does not start with meta
:
x <- c("metadata", "file1", "file2", "mass1", "mass2")
grep("^(?!meta)", x, value = TRUE, perl = TRUE)
## [1] "file1" "file2" "mass1" "mass2"
2.8 Install blogdown
devtools::install_github(‘rstudio/blogdown’)
2.9 Crate github repositories
- Create two repositories
- sources
- public, README, and R .gitignore, LICENSE
- github.io
- public, README, and , LICENSE
- sources
2.10 Setting up main rapository
Clone your web repository
Set working directory on the created folder and do not create any new file
https://git-scm.com/book/en/v2/Git-Tools-Submodules
git submodule add git@github.com:statistical-issues/statistical-issues.github.io.git public git commit -am ‘added hugo web module’ git push
blogdown::build_site() touch .nojekyll git add -A git commit -m “built web”
git clone git@github.com:statistical-issues/statistical-issues-source.git git submodule init git submodule update cd public git checkout master
2.11 How to contribute to a git repository with submodules
git clone --recursive https://github.com/chaconinc/MainProject
git clone --recursive git@github.com:statistical-issues/statistical-issues-source.git
get into your repository and to the public folder, this is where the source code for your web is located
cd statistical-issues-source/public
git checkout master
%% similar to git pull for a submodule %% git submodule update –remote DbConnector
%% git submodule update –remote –rebase
2.12 R packages
- Adding vignettes
devtools::use_vignette("my-vignette")
2.13 R profiling
Rprof("profile.out", line.profiling=TRUE)
source("test_multiple_observations.R")
Rprof(NULL)
summaryRprof("profile.out", lines = "show")
CPUPROFILE="myprof.log" R -f my-program.R
google-pprof --text /usr/lib/R/bin/exec/R myprof.log | more
google-pprof --text --focus=emcore /usr/lib/R/bin/exec/R myprof.log | more