Polish list, loops, & map() intro.

This commit is contained in:
hadley
2015-11-19 07:03:51 +13:00
parent d30bded405
commit 269867d60c
6 changed files with 212 additions and 78 deletions

28
images/embed_jpg.R Normal file
View File

@@ -0,0 +1,28 @@
is_latex <- function() {
identical(knitr::opts_knit$get('rmarkdown.pandoc.to'), "latex")
}
embed_jpg <- function(path, dpi) {
dim <- jpg_dim(path)
if (is_latex()) {
width <- round(dim[2] / dpi, 2)
knitr::asis_output(paste0(
"\\includegraphics[",
"width=", width, "in",
"]{", path, "}"
))
} else {
knitr::asis_output(paste0(
"<img src='", path, "'",
" width='", round(dim[2] / (dpi / 96)), "'",
" height='", round(dim[1] / (dpi / 96)), "'",
" />"
))
}
}
jpg_dim <- function(path) {
dim(jpeg::readJPEG(path, native = TRUE))
}

BIN
images/pepper-1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 KiB

BIN
images/pepper-2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

BIN
images/pepper-3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

BIN
images/pepper.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB