---
title: "Code for Session 3"
author: "Dr. Richard M. Crowley"
date: ""
output:
  html_notebook
---

Note that the directories used to store code are likely different on your computer, and such references will need to be changed before using any such code.

```{r helpers, warning=FALSE, message=F}
library(knitr)
library(kableExtra)
html_df <- function(text, cols=NULL, col1=FALSE, full=F) {
  if(!length(cols)) {
    cols=colnames(text)
  }
  if(!col1) {
    kable(text,"html", col.names = cols, align = c("l",rep('c',length(cols)-1))) %>%
      kable_styling(bootstrap_options = c("striped","hover"), full_width=full)
  } else {
    kable(text,"html", col.names = cols, align = c("l",rep('c',length(cols)-1))) %>%
      kable_styling(bootstrap_options = c("striped","hover"), full_width=full) %>%
      column_spec(1,bold=T)
  }
}

library(quantmod)
library(curl)
Quote <- function(name) {
  if(has_internet()) {
    quote <- getQuote(name)
    saveRDS(quote, paste0(name,'_quote.rds'))
  } else {
    quote <- readRDS(paste0(name,'_quote.rds'))
  }
  quote
}
```

```{r}
Quote('FB')
```

```{r , warning=FALSE}
options(knitr.table.format = "html") 
text <- data.frame(
  def = c("Issue shares","Purchase treasury shares","Sell treasury shares","Declare dividends","Pay dividends","Issue share dividends","Stock split"),
  asset = c("↑","↓","↑","--","↓","--","--"),
  liability = c("--","--","--","↑","↓","--","--"),
  equity = c("↑","↓","↑","↓","--","--","--")
)
html_df(text, col1=TRUE, cols=c("Transaction","Asset (↑=DR)","Liability (↑=CR)","Equity (↑=CR)"))
```

