---
title: "Rticles: Scientific Documents with Bookdown R Package"
subtitle: "www.inkaverse.com"
---

- Open the created folder
- Open the `rticles.Rproj``
- Open the `index.Rmd`
- Run the `setup` chunk
- Go Build option: `Build book`
- Wait until the book finish compile
- Check the example

After create your document, you can delete this file

***
***

# Useful code

## Bookdown

### Configuración

```{r, eval = F}
source("https://lozanoisla.com/setup.r")
url <- paste0("https://docs.google.com/spreadsheets/d/"
              , "1QziIXGOwb8cl3GaARJq6Ez6aU7vND_UHKJnFcAKx0VI")
gs <- as_sheets_id(url)
# browseURL(url)
xl <- gs %>% 
  drive_download("files/fieldbook.xlsx", overwrite = T) %>%
  pluck(2)
fb <- xl %>% 
  readxl::read_excel("prosopis")  %>% 
  rename_with(tolower) %>% 
  mutate(across(c("rep", "nacl", "temp"), ~ as.factor(.) )) %>% 
  mutate(across(where(is.factor), ~ gsub("[[:space:]]", "", .)) ) %>% 
  as.data.frame()
# str(fb)
```

```{=html}
<div id="icons" style="width: 100%; margin: auto;">
<div style="display: inline-block; width: 100%;">
<p style="text-align: center;"><a rel="noopener" href="https://raw.githubusercontent.com/Flavjack/rticles/master/index.Rmd" target="_blank"><img style="height: 50px;" title="code" src="https://www.flaticon.es/svg/static/icons/svg/2920/2920244.svg" alt="code" /></a> <span style="display: block;">codigo</span></p>
</div>
</div>
```

### Tablas

```{r, eval = F}
potato %>% 
  select(treat, geno,	bloque, leafdw:lfa) %>% 
  head(10) %>% 
  include_table(
    caption = "Water use effiency dataset import from a googlesheet"
    , notes = "@R-inti"
    , label = "__Source:__"
    )

#> cite: (Table \@ref(tab:chunk))
```

### Figuras

```{r, eval = F}
fig <- include_figure(
  figure = "files/fig-02.png"
  , caption = "Plant of *Jatropha curcas*. 
  A) Foliage.
  B) Leaf. 
  C) Fruit."
  )

fig$figure

#> cite: (Figure \@ref(fig:chunk))
#> caption: fig.cap= fig$caption
```

### Referencias

#### Especificar posición

```{html, eval = F}
::: {#refs}
:::
```

#### Citar paquetes

```{r, eval = F}
if(!file.exists("files/pkgs.bib")){write_bib(c(.packages()),'files/pkgs.bib')}
```

### PDF's

```{r, eval = F}
<embed src="files/file_name.pdf" width="100%" height="500" alt="pdf" pluginspage="http://www.adobe.com/products/acrobat/readstep2.html">
```

### Videos

```{r, eval = F}
<iframe width="100%" height="450" src="https://www.youtube.com/embed/video_id" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
```

### Articul^8^

```{r, eval=F}
file <- list.files(pattern = '*.zip')
unzip(file, overwrite = T)
list <- unzip(file, list = T)$Name
md <- grep("md$", list) 
path <- list[md]
file.rename(path, "gdoc.Rmd")
#> title: &nbsp
#> include=FALSE
#> child = "gdoc.Rmd"
#> unlink("gdoc.Rmd")
```

### Cover page

```{r, eval=FALSE}
#> yaml 
params:
  user:   'Flavio Lozano Isla'
  title:  '" Title"'
  logo:   !r if (!knitr:::is_html_output()) knitr::include_graphics('files/logo.png')
  uni:    'Universidad Nacional Agraria la Molina'
  facu:   'Facultad de Agronomía'
  type:   'Tesis para optar el título de ingeniero Agrónomo'
  date:   !r if (knitr:::is_html_output()) {format(Sys.time(), '%d %b %Y %X')}
  place:  'Lima-Perú'
  year:   '2021'
  
#> Doc body
  
:::{custom-style="uni"} 
`r params$uni` 
:::
:::{custom-style="facu"} 
`r params$facu` 
:::
:::{custom-style="logo"} 
`r params$logo` 
:::
:::{custom-style="title"} 
`r params$title` 
:::
:::{custom-style="type"} 
`r params$type` 
:::
:::{custom-style="user"} 
`r params$user` 
:::
:::{custom-style="place"} 
`r params$place` 
:::
:::{custom-style="year"} 
`r params$year` 
:::
\newpage  
```

***
***

## Git

### Importar cambios

```{bash, eval = F}
git pull
```

### Enviar cambios

```{bash, eval = F}
git add .
git commit -m "message"
git push 
```

### Re-escribir archivos locales a origen

```{bash, eval = F}
git fetch --all
git reset --hard origin/master
git pull origin master
```

### Forzar envio de cambios

```{bash, eval = F}
git push -f origin master
```

### Revertir cambios

```{bash, eval = F}
git reset --hard <commit>
```
