Skip to content

Commit

Permalink
unify targets; fix #51
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestguevarra committed Sep 1, 2024
1 parent 4e76465 commit 0074dc6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 131 deletions.
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}

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
81 changes: 18 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,95 +177,51 @@ 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
area of responsibility since 2017;

<!-- end list -->
2. Daily heat index data from various data collection points in the
Philippines;

``` mermaid
graph LR
style Graph fill:#FFFFFF00,stroke:#000000;
subgraph Graph
direction LR
x1cf596d0c4f824b5["cyclone_reports_download_files"]:::outdated --> x721677a433d907a0["cyclones_peak_data"]:::outdated
x6f87cfcc96bb274d(["cyclone_reports_links"]):::outdated --> x1cf596d0c4f824b5["cyclone_reports_download_files"]:::outdated
x721677a433d907a0["cyclones_peak_data"]:::outdated --> xdc5659ed1b9a196a(["cyclones_peak_data_csv"]):::outdated
end
```
3. Climatological extremes and normals data over time; and,

2. Daily heat index data from various data collection points in the
Philippines
4. Daily dam water level data.

<!-- end list -->
The following diagram illustrates these workflows

``` mermaid
graph LR
style Graph fill:#FFFFFF00,stroke:#000000;
subgraph Graph
direction LR
x567709ab5f0adc71(["heat_index_pubfiles_url"]):::outdated --> x56bd7c118ed46a38(["heat_index_links"]):::outdated
x56bd7c118ed46a38(["heat_index_links"]):::outdated --> x113a83dcec46090f(["heat_index_links_urls"]):::outdated
x567709ab5f0adc71(["heat_index_pubfiles_url"]):::uptodate --> x56bd7c118ed46a38(["heat_index_links"]):::outdated
xb48a3b157c96bffd(["climate_pubfiles_url"]):::uptodate --> xa37a01adfb45bd68(["climate_directory_urls"]):::uptodate
x26b861c7a0a21b52["climate_pdf_urls"]:::uptodate --> xc044beb81380bb4a["climate_download_files"]:::uptodate
xc432bd4e21a7b9fa(["heat_index_links_dates"]):::outdated --> x4f749438c4164b8e["heat_index_download_files"]:::outdated
x113a83dcec46090f(["heat_index_links_urls"]):::outdated --> x4f749438c4164b8e["heat_index_download_files"]:::outdated
x56bd7c118ed46a38(["heat_index_links"]):::outdated --> xc432bd4e21a7b9fa(["heat_index_links_dates"]):::outdated
end
```

3. Climatological extremes and normals data over time

<!-- end list -->

``` mermaid
graph LR
style Graph fill:#FFFFFF00,stroke:#000000;
subgraph Graph
direction LR
xb48a3b157c96bffd(["climate_pubfiles_url"]):::uptodate --> xa37a01adfb45bd68(["climate_directory_urls"]):::uptodate
xc044beb81380bb4a["climate_download_files"]:::uptodate --> x84b857e732ff3c29(["pagasa_weather_stations"]):::outdated
xa37a01adfb45bd68(["climate_directory_urls"]):::uptodate --> x26b861c7a0a21b52["climate_pdf_urls"]:::uptodate
x26b861c7a0a21b52["climate_pdf_urls"]:::uptodate --> xc044beb81380bb4a["climate_download_files"]:::uptodate
xc044beb81380bb4a["climate_download_files"]:::uptodate --> xe06460aefd475ca2(["climate_data_extremes_2020"]):::outdated
xc044beb81380bb4a["climate_download_files"]:::uptodate --> xc83b489a1c433852(["climate_data_extremes_2021"]):::outdated
xc044beb81380bb4a["climate_download_files"]:::uptodate --> x9b64b30afbfc8ff9(["climate_data_extremes_2022"]):::outdated
xc044beb81380bb4a["climate_download_files"]:::uptodate --> xf620d5783ff15609(["climate_data_extremes_2023"]):::outdated
xc044beb81380bb4a["climate_download_files"]:::uptodate --> x42da7c0722c063a6(["climate_data_normals_1991_2020"]):::outdated
end
```

4. Daily dam water level data

<!-- end list -->

``` mermaid
graph LR
style Graph fill:#FFFFFF00,stroke:#000000;
subgraph Graph
direction LR
x0de96327cc07b160(["dam_level_data"]):::outdated --> x202d34e7af3ea1c1(["dam_level_data_raw_csv"]):::outdated
xd2c3c65ab78d2c70(["dam_level_data_processed"]):::uptodate --> xfa0b497de91938bb(["dam_level_data_csv"]):::uptodate
x7255575025352eb6(["dam_level_data_files"]):::uptodate --> xd2c3c65ab78d2c70(["dam_level_data_processed"]):::uptodate
xc77bb431ac7c3081(["dam_level_url"]):::uptodate --> x0de96327cc07b160(["dam_level_data"]):::outdated
end
```

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
Expand All @@ -276,13 +232,13 @@ 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
Expand All @@ -295,11 +251,10 @@ 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.
Expand Down
3 changes: 2 additions & 1 deletion _targets_dam.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ output_targets <- tar_plan(
### Output processed dam level data as CSV ----
tar_target(
name = dam_level_data_csv,
command = dam_archive_processed(dam_level_data_processed)
command = dam_archive_processed(dam_level_data_processed),
format = "file"
)
)

Expand Down
7 changes: 1 addition & 6 deletions _targets_releases.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ release_targets <- tar_plan(
tar_target(
name = paglaom_weekly_release,
command = paglaom_upload_weekly_release(
climate_download_files,
cyclone_reports_download_files,
dam_level_data_files,
heat_index_download_files,
#tag = paglaom_weekly_release_tag
tag = "1.8.34"
tag = paglaom_weekly_release_tag
)
)
)

0 comments on commit 0074dc6

Please sign in to comment.