Skip to content

Commit

Permalink
Add function reference, close #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Apr 22, 2024
1 parent fd588c9 commit 11fc4fc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Generated by roxygen2: do not edit by hand

export(download_and_read)
16 changes: 14 additions & 2 deletions R/opsnap.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
download_and_read = function(u, remove_nas = TRUE, dir = "raw_data/west-yorkshire", filter_nas = FALSE) {
#' Download and read data from opsnap project
#'
#' @param u URL of data
#' @param remove_nas Remove NA values?
#' @param dir Download directory
#' @return Data frame
#' @export
#' @examples
#' if (FALSE) {
#' u = "https://www.westyorkshire.police.uk/sites/default/files/2023-10/operation_snap_july-sept_2023.xlsx"
#' download_and_read(, dir = ".")
#' }
download_and_read = function(u, remove_nas = TRUE, dir = "raw_data/west-yorkshire") {
tmp = file.path(dir, basename(u))
if (!file.exists(tmp)) {
utils::download.file(u, tmp, mode = "wb")
Expand All @@ -8,7 +20,7 @@ download_and_read = function(u, remove_nas = TRUE, dir = "raw_data/west-yorkshir
})
names(d) = clean_names(names(d))
d = select_columns(d)
if (filter_nas) {
if (remove_nas) {
d = filter_nas(d)
}
return(d)
Expand Down
27 changes: 27 additions & 0 deletions man/download_and_read.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 11fc4fc

Please sign in to comment.