Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Commit

Permalink
Change the code for specifying the place to save the model: from docs…
Browse files Browse the repository at this point in the history
… to data (as suggested in issue #38)
  • Loading branch information
qiyangqd committed Mar 24, 2020
1 parent eb944ae commit 4147df3
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ images/corr.png images/facted_hist.png images/heatmap.png images/season_PM2.5.pn
Rscript scripts/eda.R --raw_path="data/raw_data.csv" --clean_path="data/cleaned_data.csv" --image_folder_path="images"

# Generate model
docs/model.rds : data/cleaned_data.csv scripts/model.R
Rscript scripts/model.R --clean_path="data/cleaned_data.csv" --model_path="docs/model.rds"
data/model.rds : data/cleaned_data.csv scripts/model.R
Rscript scripts/model.R --clean_path="data/cleaned_data.csv" --model_path="data/model.rds"

# Knit report
docs/finalreport.html docs/finalreport.pdf docs/finalreport.md : images/corr.png images/facted_hist.png images/heatmap.png images/season_PM2.5.png images/year_PM2.5.png docs/finalreport.Rmd data/cleaned_data.csv data/raw_data.csv scripts/knit.R docs/model.rds
docs/finalreport.html docs/finalreport.pdf docs/finalreport.md : images/corr.png images/facted_hist.png images/heatmap.png images/season_PM2.5.png images/year_PM2.5.png docs/finalreport.Rmd data/cleaned_data.csv data/raw_data.csv scripts/knit.R data/model.rds
Rscript scripts/knit.R --rmd_path="docs/finalreport.Rmd"

# Clean targets
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ __tests__: Tests for functions.
`Rscript scripts/eda.R --raw_path="data/raw_data.csv" --clean_path="data/cleaned_data.csv" --image_folder_path="images"`

- [model.R](https://stat547-ubc-2019-20.github.io/group_12_qiyangqd_xiaoyuanf/scripts/model.R): Run a linear regression and save the model in a user defined location.
`Rscript scripts/model.R --clean_path="data/cleaned_data.csv" --model_path="docs/model.rds"`
`Rscript scripts/model.R --clean_path="data/cleaned_data.csv" --model_path="data/model.rds"`

- [knit.R](https://stat547-ubc-2019-20.github.io/group_12_qiyangqd_xiaoyuanf/scripts/knit.R): Knit the final report.
`Rscript scripts/knit.R --rmd_path="docs/finalreport.Rmd"`
Expand Down
Binary file modified data/model.rds
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/finalreport.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ The purpose of the line chart was to show the change of `PM2.5` concentration ac
## Analysis methods

```{r}
lm <- readRDS(file=here::here("docs", "model.rds"))
lm <- readRDS(file=here::here("data", "model.rds"))
tidy(lm)
```
```{r}
Expand Down
2 changes: 1 addition & 1 deletion docs/finalreport.html
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ <h3>5.Line chart</h3>
</div>
<div id="analysis-methods" class="section level2">
<h2>Analysis methods</h2>
<pre class="r"><code>lm &lt;- readRDS(file=here::here(&quot;docs&quot;, &quot;model.rds&quot;))
<pre class="r"><code>lm &lt;- readRDS(file=here::here(&quot;data&quot;, &quot;model.rds&quot;))
tidy(lm)</code></pre>
<pre><code>## # A tibble: 7 x 5
## term estimate std.error statistic p.value
Expand Down
2 changes: 1 addition & 1 deletion docs/finalreport.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ The purpose of the line chart was to show the change of `PM2.5` concentration ac


```r
lm <- readRDS(file=here::here("docs", "model.rds"))
lm <- readRDS(file=here::here("data", "model.rds"))
tidy(lm)
```

Expand Down
Binary file modified docs/finalreport.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/finalreport.tex
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ \subsection{Analysis methods}\label{analysis-methods}}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{lm <-}\StringTok{ }\KeywordTok{readRDS}\NormalTok{(}\DataTypeTok{file=}\NormalTok{here}\OperatorTok{::}\KeywordTok{here}\NormalTok{(}\StringTok{"docs"}\NormalTok{, }\StringTok{"model.rds"}\NormalTok{))}
\NormalTok{lm <-}\StringTok{ }\KeywordTok{readRDS}\NormalTok{(}\DataTypeTok{file=}\NormalTok{here}\OperatorTok{::}\KeywordTok{here}\NormalTok{(}\StringTok{"data"}\NormalTok{, }\StringTok{"model.rds"}\NormalTok{))}
\KeywordTok{tidy}\NormalTok{(lm)}
\end{Highlighting}
\end{Shaded}
Expand Down
Binary file removed docs/model.rds
Binary file not shown.
4 changes: 2 additions & 2 deletions scripts/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Usage: model.R --clean_path=<clean_data_path> --model_path=<model_path>
"->doc

# Load packages
c <- c("tidyverse", "here", "docopt") # Create package list
c <- c("tidyverse", "here", "docopt", "glue") # Create package list
invisible(lapply(c, require, character.only = TRUE))

opt <- docopt(doc)
Expand All @@ -24,7 +24,7 @@ main <- function(clean_path, model_path) {
saveRDS(model, file = here(model_path))

# message for users
print("Linear regression has run successfully!")
print(glue("Linear regression has run successfully, and the model has been saved in ", model_path, "."))
}


Expand Down

0 comments on commit 4147df3

Please sign in to comment.