Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor targets workflow #53

Merged
merged 4 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy-targets-dam.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

- name: Run workflow
run: |
targets::tar_make(script = "_targets_dam.R")
targets::tar_make(dam_level_data_raw_csv)
shell: Rscript {0}

- name: Commit and push files
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/deploy-targets-releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ jobs:

- name: Run workflows
run: |
targets::tar_make(script = "_targets_climate.R")
targets::tar_make(script = "_targets_cyclones.R")
targets::tar_make(script = "_targets_dam.R")
targets::tar_make(climate_download_files)
targets::tar_make(cyclone_reports_download_files)
targets::tar_make(dam_level_data_raw_csv)
shell: Rscript {0}

- name: Create weekly data release
run: |
targets::tar_make(script = "_targets_releases.R")
targets::tar_make(paglaom_weekly_release)
shell: Rscript {0}

2 changes: 1 addition & 1 deletion .github/workflows/test-targets-climate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ jobs:

- name: Run workflow
run: |
targets::tar_make(script = "_targets_climate.R")
targets::tar_make(dplyr::starts_with("climate"))
shell: Rscript {0}
2 changes: 1 addition & 1 deletion .github/workflows/test-targets-cyclones.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ jobs:

- name: Run workflow
run: |
targets::tar_make(script = "_targets_cyclones.R")
targets::tar_make(dplyr::starts_with("cyclone"))
shell: Rscript {0}
2 changes: 1 addition & 1 deletion .github/workflows/test-targets-dam.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ jobs:

- name: Run workflow
run: |
targets::tar_make(script = "_targets_dam.R")
targets::tar_make(dplyr::starts_with("dam"))
shell: Rscript {0}
48 changes: 0 additions & 48 deletions .github/workflows/test-targets-workflow.yml

This file was deleted.

32 changes: 12 additions & 20 deletions R/pagasa_releases.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ paglaom_create_weekly_release <- function(repo = "panukatan/paglaom",
#' Create data upload to GitHub
#'

paglaom_upload_weekly_release <- function(climate_download_files,
cyclone_reports_download_files,
dam_level_data_files,
heat_index_download_files,
repo = "panukatan/paglaom",
paglaom_upload_weekly_release <- function(repo = "panukatan/paglaom",
tag) {
zipdir <- tempdir()
zip_climate <- file.path(zipdir, "climate.zip")
Expand All @@ -80,36 +76,32 @@ paglaom_upload_weekly_release <- function(climate_download_files,
## zip climate files ----
zip(
zip_climate,
# files = list.files(
# path = "data-raw/climate", full.names = TRUE, recursive = TRUE)
files = climate_download_files
files = list.files(
path = "data-raw/climate", full.names = TRUE, recursive = TRUE)
)

## zip cyclones files ----
zip(
zip_cyclones,
# files = list.files(
# path = "data-raw/cyclones", full.names = TRUE, recursive = TRUE
# )
files = cyclone_reports_download_files
files = list.files(
path = "data-raw/cyclones", full.names = TRUE, recursive = TRUE
)
)

## zip dam files ----
zip(
zip_dam,
# files = list.files(
# path = "data-raw/dam", full.names = TRUE, recursive = TRUE
# )
files = dam_level_data_files
files = list.files(
path = "data-raw/dam", full.names = TRUE, recursive = TRUE
)
)

## zip heat files ----
zip(
zip_heat,
# files = list.files(
# path = "data-raw/heat_index", full.names = TRUE, recursive = TRUE
# )
files = heat_index_download_files
files = list.files(
path = "data-raw/heat_index", full.names = TRUE, recursive = TRUE
)
)

lapply(
Expand Down
76 changes: 19 additions & 57 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -110,117 +110,79 @@ to install all R package dependencies.

Currently, the project has workflows that curate the following datasets:

1. Tropical cyclones data for various cyclones entering the Philippine area of responsibility since 2017
1. Tropical cyclones data for various cyclones entering the Philippine area of responsibility since 2017;

```{r cyclones_workflow, echo = FALSE, message = FALSE, results = 'asis'}
cat(
"```mermaid",
targets::tar_mermaid(
targets_only = TRUE, color = FALSE, legend = FALSE,
script = "_targets_cyclones.R"
),
"```",
sep = "\n"
)
```


2. Daily heat index data from various data collection points in the Philippines

```{r heat_workflow, echo = FALSE, message = FALSE, results = 'asis'}
cat(
"```mermaid",
targets::tar_mermaid(
targets_only = TRUE, color = FALSE, legend = FALSE,
script = "_targets_heat.R"
),
"```",
sep = "\n"
)
```
2. Daily heat index data from various data collection points in the Philippines;

3. Climatological extremes and normals data over time; and,

3. Climatological extremes and normals data over time
4. Daily dam water level data.

```{r climate_workflow, echo = FALSE, message = FALSE, results = 'asis'}
cat(
"```mermaid",
targets::tar_mermaid(
targets_only = TRUE, color = FALSE, legend = FALSE,
script = "_targets_climate.R"
),
"```",
sep = "\n"
)
```
The following diagram illustrates these workflows


4. Daily dam water level data

```{r dam_workflow, echo = FALSE, message = FALSE, results = 'asis'}
```{r overall_workflow, echo = FALSE, message = FALSE, results = 'asis'}
cat(
"```mermaid",
targets::tar_mermaid(
targets_only = TRUE, color = FALSE, legend = FALSE,
script = "_targets_dam.R"
targets_only = TRUE,
names = dplyr::starts_with(c("climate", "cyclone", "dam", "heat")),
color = FALSE, legend = FALSE
),
"```",
sep = "\n"
)
```


To run any of these workflows, run the following command on the R console:

```R
targets::tar_make(script = "NAME_OF_TARGET_SCRIPT_R_FILE")
targets::tar_make(dplyr::starts_with("PREFIX"))
```

replacing `"NAME_OF_TARGET_SCRIPT_R_FILE"` with the name of the target script file for the specific workflow. For example, to run the cyclones workflow from R console:
replacing `"PREFIX"` with the keyword for the type of data. For example, to run the cyclones workflow from R console:

```R
targets::tar_make(script = "_targets_cyclones.R")
targets::tar_make(dplyr::starts_with("cyclone"))
```

or from the command line/terminal as follows:

```Bash
Rscript -e "targets::tar_make(script = "_targets_cyclones.R)"
Rscript -e "targets::tar_make(dplyr::starts_with('cyclone'))"
```

Running specific components of a workflow involves specifying a target name or target names of the components you want to run. You should be able to run a full workflow path by just specifying the name of the last target in the workflow sequence. For example, the following will run the entire cyclones data workflow (as an alternative to what is shown above):

```R
targets::tar_make(cyclones_peak_data_csv, script = "_targets_cyclones.R")
targets::tar_make(cyclones_peak_data_csv)
```

or from the command line/terminal as follows:

```Bash
Rscript -e "targets::tar_make(cyclones_peak_data_csv, script = "_targets_cyclones.R")"
Rscript -e "targets::tar_make(cyclones_peak_data_csv)"
```

The target `cyclones_peak_data_csv` is the last target of the cyclones data workflow. Hence, to be able to produce the `cyclones_peak_data_csv` target requires running this series of linked targets.

If you would like to run a set of interrelated but not fully linked targets, you will need to specify more than one target name. For this, you can use `tidyselect` approaches to name targets to be run. For example:

```R
targets::tar_make(dplyr::starts_with("cyclone"), script = "_targets_cyclones.R")
targets::tar_make(dplyr::starts_with(c("cyclone", "dam"))
```

will run all targets in the cyclones data workflow whose names start with *"cyclone"*.
will run all targets in the cyclones and dam levels data workflow.

The project also has a workflow for weekly GitHub release of the various raw datasets.

```{r release_workflow, echo = FALSE, message = FALSE, results = 'asis'}
cat(
"```mermaid",
targets::tar_mermaid(
targets_only = TRUE, color = FALSE, legend = FALSE,
script = "_targets_releases.R"
targets_only = TRUE, names = dplyr::starts_with("paglaom_weekly"),
color = FALSE, legend = FALSE
),
"```",

sep = "\n"
)
```
Expand Down
Loading