generated from OxfordIHTM/ihtm-targets-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8060fcf
commit 9198062
Showing
14 changed files
with
223 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#' | ||
#' Retrieve download links for yearly cyclones reports | ||
#' | ||
#' @param url | ||
#' | ||
#' @returns A vector of URL links to the yearly cyclones reports | ||
#' | ||
#' | ||
|
||
cyclones_get_report_links <- function(url = "https://www.pagasa.dost.gov.ph/tropical-cyclone/publications/annual-report") { | ||
httr::config(ssl_verifypeer = 0L) |> | ||
httr::set_config() | ||
|
||
url_session <- rvest::session(url) | ||
|
||
url_session |> | ||
rvest::html_elements(css = ".panel .panel-body li a") |> | ||
rvest::html_attr(name = "href") | ||
} | ||
|
||
|
||
#' | ||
#' Download cyclones reports | ||
#' | ||
#' @param url_link | ||
#' @param directory | ||
#' | ||
#' @returns File downloaded to specified path (invisible). A character value for | ||
#' path to downloaded file | ||
#' | ||
|
||
cyclones_download_report <- function(url_link, directory) { | ||
## Check if directory exists; if not create ---- | ||
if (!dir.exists(directory)) | ||
dir.create(directory, showWarnings = FALSE, recursive = TRUE) | ||
|
||
## Create file path to download ---- | ||
path <- file.path(directory, basename(url_link)) | ||
|
||
## Download file/s ---- | ||
Map( | ||
f = download.file, | ||
url = as.list(url_link), | ||
destfile = as.list(path) | ||
) | ||
|
||
## Return path/s ---- | ||
path | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
cyclones: | ||
script: _targets_cyclones.R | ||
store: _targets_cyclones | ||
heat: | ||
script: _targets_heat.R | ||
store: _targets_heat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
################################################################################ | ||
# | ||
# General Targets Workflow | ||
# | ||
################################################################################ | ||
|
||
## Load libraries and custom functions ----------------------------------------- | ||
suppressPackageStartupMessages(source("packages.R")) | ||
for (f in list.files(here::here("R"), full.names = TRUE)) source (f) | ||
|
||
## Create targets -------------------------------------------------------------- | ||
|
||
### Download targets ---- | ||
|
||
download_targets <- tar_plan( | ||
tar_target( | ||
name = cyclone_reports_links, | ||
command = cyclones_get_report_links() | ||
), | ||
tar_target( | ||
name = cyclone_reports_download_files, | ||
command = cyclones_download_report( | ||
url_link = cyclone_reports_links, | ||
directory = "data-raw/cyclones" | ||
), | ||
pattern = map(cyclone_reports_links), | ||
format = "file" | ||
) | ||
) | ||
|
||
### Data targets | ||
data_targets <- tar_plan( | ||
|
||
) | ||
|
||
|
||
### Processing targets | ||
processing_targets <- tar_plan( | ||
|
||
) | ||
|
||
|
||
### Analysis targets | ||
analysis_targets <- tar_plan( | ||
|
||
) | ||
|
||
|
||
### Output targets | ||
output_targets <- tar_plan( | ||
|
||
) | ||
|
||
|
||
### Reporting targets | ||
report_targets <- tar_plan( | ||
|
||
) | ||
|
||
|
||
### Deploy targets | ||
deploy_targets <- tar_plan( | ||
|
||
) | ||
|
||
|
||
## List targets ---------------------------------------------------------------- | ||
all_targets() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
* | ||
!.gitignore | ||
!meta | ||
meta/* | ||
!meta/meta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name|type|data|command|depend|seed|path|time|size|bytes|format|repository|iteration|parent|children|seconds|warnings|error | ||
.Random.seed|object|1617e1b0d9b19ac3||||||||||||||| | ||
all_targets|function|b6dd8c08c18a0132||||||||||||||| | ||
analysis_targets|object|ef46db3751d8e999||||||||||||||| | ||
cyclone_reports_download_files|pattern|0aba2b50cff34e6a|f6ca15f19248c12f||1643365027||||50315072|file|local|vector||cyclone_reports_download_files_1342b9b0*cyclone_reports_download_files_3de468d2*cyclone_reports_download_files_1f710163*cyclone_reports_download_files_3a21c11c|111.33|| | ||
cyclone_reports_download_files_1342b9b0|branch|60729b809d91b79c|f6ca15f19248c12f|06035e6aa816dd5c|1498400784|data-raw/cyclones/PAGASA_ARTC_2017.pdf|t19818.7964824806s|5313c5a66b4edadc|5460545|file|local|vector|cyclone_reports_download_files||31.722|| | ||
cyclone_reports_download_files_1f710163|branch|de688a74a6ff77fd|f6ca15f19248c12f|06035e6aa816dd5c|226425042|data-raw/cyclones/PAGASA_ARTC_2019.pdf|t19818.7971196276s|65928e670053fd1b|12015407|file|local|vector|cyclone_reports_download_files||26.517|| | ||
cyclone_reports_download_files_3a21c11c|branch|db3ea6470ddc52b2|f6ca15f19248c12f|06035e6aa816dd5c|-825356566|data-raw/cyclones/PAGASA_ARTC_2020.pdf|t19818.7974045428s|a566e253d0d1ff29|15191585|file|local|vector|cyclone_reports_download_files||24.597|| | ||
cyclone_reports_download_files_3de468d2|branch|bc6d333cb1096ac5|f6ca15f19248c12f|06035e6aa816dd5c|1448407431|data-raw/cyclones/PAGASA_ARTC_2018.pdf|t19818.7968125359s|dab08093bc4d0be0|17647535|file|local|vector|cyclone_reports_download_files||28.494|| | ||
cyclone_reports_links|stem|976139e21c1457e1|50c3fa41d6ec29a2|3c2674030d3a4120|-147333770||t19818.7875375608s|4859fc503e8e9e17|155|rds|local|vector|||4.655|| | ||
cyclones_download_report|function|cb072b709121376a||||||||||||||| | ||
cyclones_get_report_links|function|4ae6238e54fa5d98||||||||||||||| | ||
data_targets|object|ef46db3751d8e999||||||||||||||| | ||
deploy_targets|object|ef46db3751d8e999||||||||||||||| | ||
download_targets|object|d135cd3318e807a0||||||||||||||| | ||
f|object|2cca7bbc806ca10a||||||||||||||| | ||
get_cyclone_report_links|function|4ae6238e54fa5d98||||||||||||||| | ||
output_targets|object|ef46db3751d8e999||||||||||||||| | ||
processing_targets|object|ef46db3751d8e999||||||||||||||| | ||
report_targets|object|ef46db3751d8e999||||||||||||||| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
################################################################################ | ||
# | ||
# General Targets Workflow | ||
# | ||
################################################################################ | ||
|
||
## Load libraries and custom functions ----------------------------------------- | ||
suppressPackageStartupMessages(source("packages.R")) | ||
for (f in list.files(here::here("R"), full.names = TRUE)) source (f) | ||
|
||
## Create targets and list targets objects ------------------------------------- | ||
|
||
### Data targets | ||
data_targets <- tar_plan( | ||
|
||
) | ||
|
||
|
||
### Processing targets | ||
processing_targets <- tar_plan( | ||
|
||
) | ||
|
||
|
||
### Analysis targets | ||
analysis_targets <- tar_plan( | ||
|
||
) | ||
|
||
|
||
### Output targets | ||
output_targets <- tar_plan( | ||
|
||
) | ||
|
||
|
||
### Reporting targets | ||
report_targets <- tar_plan( | ||
|
||
) | ||
|
||
|
||
### Deploy targets | ||
deploy_targets <- tar_plan( | ||
|
||
) | ||
|
||
|
||
## List targets | ||
all_targets() |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters