# key setups
library(sqldf) # to use sql syntax with data frames
library(knitr) # knitr for kable tables
library(kableExtra) # pretty tables
library(sf) # simple features (GIS)
library(leaflet) # nice maps
library(tools) # md5sum

# captions
library(captioner)
table_nums <- captioner(prefix = "Table")
figure_nums <- captioner(prefix = "Figure")

# for having DIV tags
knitr::knit_hooks$set(class = function(before, options, envir) {
  if(before){
    sprintf("<div class = '%s'>", options$class)
  }else{
    "</div>"
  }
})

knitr::opts_chunk$set(warning = FALSE, message = FALSE)

1 Introduction

2 Methods

2.1 Data

2.2 Analysis

3 Results

3.1 A table

See Table 1

Table 1: My caption

irishead <- head(iris)
kable(irishead, format = "html") %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"), full_width = F, position = "left")
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
5.0 3.6 1.4 0.2 setosa
5.4 3.9 1.7 0.4 setosa

3.2 A leaflet map

See Figure 1

# the Space Needle
snxy <- data.frame(name = "Space Needle", x = -122.3493, y = 47.6205)
space_needle <- st_as_sf(snxy, coords = c("x", "y"), crs = 4326)

# a leaflet
m <- leaflet() %>% 
    addTiles() %>% 
    addCircleMarkers(data = space_needle)
m

 
Figure 1: A simple leaflet map with the Space Needle as a markerpoint

3.3 A figure with black outlines

An image is shown below (Figure 2).

 
Figure 2: CSDE Logo

4 Discussion

5 Conclusions

6 Source code

6.1 This document

cat(readLines("//udrive.uw.edu/udrive/csde502_winter_2021/week_01.Rmd"), sep = '\n')
---
title: "Week 01"
author: "[Phil Hurvitz](mailto:phurvitz@uw.edu)"
date: '`r format(Sys.time(), "%Y-%m-%d %H:%M")`'
header-includes: #allows you to add in your own Latex packages
- \usepackage{float} #use the 'float' package
- \floatplacement{figure}{H} #make every figure with caption = h
output: 
    html_document:
        number_sections: true
        self_contained: true
        code_folding: hide
        toc: true
        toc_float:
            collapsed: true
            smooth_scroll: false
    pdf_document:
        number_sections: true
        toc: true
        fig_cap: yes
        keep_tex: yes
urlcolor: blue        
---

<!--these following settings control width and also make a DIV tag for black outlines for figures-->
<style type="text/css">
.main-container {
  max-width: 2400px !important;
  margin-left: auto;
  margin-right: auto;
}
</style>

<style>
.outline {
   background-color: #000000;
   padding:1px;
   display: inline-block;
}
</style>

```{r setup, message=FALSE}
# key setups
library(sqldf) # to use sql syntax with data frames
library(knitr) # knitr for kable tables
library(kableExtra) # pretty tables
library(sf) # simple features (GIS)
library(leaflet) # nice maps
library(tools) # md5sum

# captions
library(captioner)
table_nums <- captioner(prefix = "Table")
figure_nums <- captioner(prefix = "Figure")

# for having DIV tags
knitr::knit_hooks$set(class = function(before, options, envir) {
  if(before){
    sprintf("<div class = '%s'>", options$class)
  }else{
    "</div>"
  }
})

knitr::opts_chunk$set(warning = FALSE, message = FALSE)
```

<!-- for a wide presentation -->
<style type="text/css">
.main-container {
  max-width: 2400px !important;
  margin-left: auto;
  margin-right: auto;
}
</style>

<!-- a DIV for black outline, good for figures-->
<style>
.outline {
   background-color: #000000;
   padding:1px;
   display: inline-block;
}
</style>

# Introduction

<!--This is a newline:

\  

(a backslash with 2 spaces)
-->

# Methods

## Data

## Analysis

# Results

## A table

See `r table_nums(name = "tcap0", display = "cite")`

_`r table_nums(name = "tcap0", caption = "My caption")`_

```{r}
irishead <- head(iris)
kable(irishead, format = "html") %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"), full_width = F, position = "left")
``` 

## A leaflet map

See _`r figure_nums(name = "spaceneedle", display = "cite")`_ 

```{r}
# the Space Needle
snxy <- data.frame(name = "Space Needle", x = -122.3493, y = 47.6205)
space_needle <- st_as_sf(snxy, coords = c("x", "y"), crs = 4326)

# a leaflet
m <- leaflet() %>% 
    addTiles() %>% 
    addCircleMarkers(data = space_needle)
m
```
\    
_`r figure_nums(name = "spaceneedle", caption = "A simple leaflet map with the Space Needle as a markerpoint")`_

## A figure with black outlines
An image is shown below (`r figure_nums(name = "csdelogo", display = "cite")`).

<div class = "outline">
![](https://csde.washington.edu/wp-content/uploads/2016/08/csdelogo-110x110.png)
</div>
\      
_`r figure_nums(name = "csdelogo", caption = "CSDE Logo")`_

# Discussion

# Conclusions

# Source code
## This document
```{r comment=''}
cat(readLines("//udrive.uw.edu/udrive/csde502_winter_2021/week_01.Rmd"), sep = '\n')
```