Skip to content

Commit

Permalink
output
Browse files Browse the repository at this point in the history
jrosell committed Dec 28, 2023
1 parent 15534c5 commit 3e2a01a
Showing 9 changed files with 48 additions and 20 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -12,8 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: docker build -t my-image-name .
- run: docker run --rm --name my_pipeline_container -v /github/workspace/fig/:/home/fig/:rw my-image-name
- run: docker run --rm --name my_pipeline_container -v /github/workspace/output/:/output/:rw my-image-name
- uses: actions/upload-artifact@v3
with:
name: my-figures
path: /github/workspace/fig/
path: /github/workspace/output/
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ RUN apt-get update && apt-get install -y \

RUN R -e "install.packages(c('dplyr', 'purrr', 'curl', 'readr', 'stringr', 'ggplot2', 'janitor', 'targets'))"

RUN mkdir /home/fig
RUN mkdir /output

COPY _targets.R /_targets.R

16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# playground
# playground

## Run in a local computer

```
$ git clone https://github.com/jrosell/playground
$ cd playground
$ docker build -t my-image-name . && docker run --rm --name my_pipeline_container -v $(pwd)/output:/output/:rw my-image-name
```

## Run in Github Actions

Look the [.github/workflows/main.yml](.github/workflows/main.yml) file.
6 changes: 3 additions & 3 deletions _targets.R
Original file line number Diff line number Diff line change
@@ -58,19 +58,19 @@ list(

tar_target(
luxembourg_saved_plot,
save_plot("/home/fig/luxembourg.png", lux_plot),
save_plot("output/luxembourg.png", lux_plot),
format = "file"
),

tar_target(
canton_saved_plot,
save_plot("/home/fig/canton.png", canton_plot),
save_plot("output/canton.png", canton_plot),
format = "file"
),

tar_target(
commune_saved_plot,
save_plot("/home/fig/commune.png", commune_plot),
save_plot("output/commune.png", commune_plot),
format = "file"
)

26 changes: 14 additions & 12 deletions functions.R
Original file line number Diff line number Diff line change
@@ -54,7 +54,8 @@ clean_unemp <- function(unemp_data,
# This is a helper function to clean the data
clean_data <- function(x){
print("clean_data")
print(x)
print("str")
print(str(x))
x |>
janitor::clean_names() |>
mutate(level = case_when(
@@ -77,17 +78,18 @@ clean_data <- function(x){

# This reads in the data.
get_data <- function(){
print("unemp_data")
urls <- list(
"https://raw.githubusercontent.com/b-rodrigues/modern_R/master/datasets/unemployment/unemp_2013.csv",
"https://raw.githubusercontent.com/b-rodrigues/modern_R/master/datasets/unemployment/unemp_2014.csv",
"https://raw.githubusercontent.com/b-rodrigues/modern_R/master/datasets/unemployment/unemp_2015.csv",
"https://raw.githubusercontent.com/b-rodrigues/modern_R/master/datasets/unemployment/unemp_2016.csv"
)
print(urls)
urls |>
purrr::map_dfr(readr::read_csv) %>%
purrr::map_dfr(clean_data)
print("unemp_data")
urls <- list(
"https://raw.githubusercontent.com/b-rodrigues/modern_R/master/datasets/unemployment/unemp_2013.csv",
"https://raw.githubusercontent.com/b-rodrigues/modern_R/master/datasets/unemployment/unemp_2014.csv",
"https://raw.githubusercontent.com/b-rodrigues/modern_R/master/datasets/unemployment/unemp_2015.csv",
"https://raw.githubusercontent.com/b-rodrigues/modern_R/master/datasets/unemployment/unemp_2016.csv"
)
print(urls)
urls |>
purrr::map(readr::read_csv) %>%
purrr::map(clean_data) %>%
purrr::list_rbind()
}

# This plots the data
Binary file added output/canton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/commune.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/luxembourg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions playground.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 4
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

0 comments on commit 3e2a01a

Please sign in to comment.