---
title: "Project X Solutions"
output:
  pdf_document: default
---

```{r, include=F}
# Run this code chunk first to activate the course Python environment.
# Do not remove this. It will not show up in your compiled PDF.
datamine_py()
library(reticulate)

# Install packages if not already installed.
list.of.packages <- c("knitr")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)

# Remove ## from output.
library(knitr)
opts_chunk$set(comment = NA)

# Wrap output that is too long using r code chunk option linewidth=80
hook_output = knit_hooks$get('output')
knit_hooks$set(output = function(x, options) {
  # this hook is used only when the linewidth option is not NULL
  if (!is.null(n <- options$linewidth)) {
    x = knitr:::split_lines(x)
    # any lines wider than n should be wrapped
    if (any(nchar(x) > n)) x = strwrap(x, width = n)
    x = paste(x, collapse = '\n')
  }
  hook_output(x, options)
})
```

## (Student name here)

## Collaborators: (Collaborators listed here. Include names, which part of the project you gave or sought help with, and how you helped or were helped.)
## TA help: (TA help sought (if any) here. Include names, which part of the project you sought help with, and how you were helped.)
## Online resources used: (List of links/resources (if any) here. Include web addresses, which part of the project the resource helped with, and how you were helped.)

### Question 1

This is an example of a question where we need to include R code.

```{r, linewidth=80}
# Here is some R code.
my_variable <- c(1,2,3)
my_variable
```

### Question 2

This is an example of a question where we need to include UNIX commands.

```{bash, linewidth=80}
# Here are some bash commands.
ls | wc -w
```

### Question 3

This is an example where we just use some simple Markdown.

- First item
- Second item

You can find a link [here](https://datamine.purdue.edu/).

### Question 4

This is an example of a question where we need to include Python code.

**Important note:** Make sure to run the `datamine_py` function prior to running a Python code chunk.

```{python, linewidth=80}
import pandas as pd

dat = pd.read_csv('/class/datamine/data/amazon/amazon_fine_food_reviews.csv')
dat.head()
```

### Question 5

This is an example of a question where we need to use SQL from within R.

```{r, linewidth=80}
library(RSQLite)

# This is where we define and initiate a connection.
con <- dbConnect(RSQLite::SQLite(), "/class/datamine/data/chinook/chinook.db")

# We can then use the connection to run queries.
dat <- dbGetQuery(con, "SELECT * FROM employees LIMIT 5;")
head(dat)
```

Alternatively, you can use `con` to run SQL directly in a code chunk.

```{sql, connection=con, linewidth=80}
SELECT Name FROM tracks LIMIT 5;
```

## Pledge

By submitting this work I hereby pledge that this is my own, personal work. I've acknowledged in the designated place at the top of this file all sources that I used to complete said work, including but not limited to: online resources, books, and electronic communications. I've noted all collaboration with fellow students and/or TA's. I did not copy or plagiarize another's work.

> As a Boilermaker pursuing academic excellence, I pledge to be honest and true in all that I do. Accountable together – We are Purdue.
