-
Notifications
You must be signed in to change notification settings - Fork 18
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
A few fixes for some issues #244
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
get_url = function(file_name = "", | ||
domain = "https://data.dft.gov.uk", | ||
directory = "road-accidents-safety-data" | ||
) { | ||
) { | ||
path = file.path(domain, directory, file_name) | ||
path | ||
} | ||
|
@@ -43,11 +43,12 @@ current_year = function() as.integer(format(format(Sys.Date(), "%Y"))) | |
find_file_name = function(years = NULL, type = NULL) { | ||
result = unlist(stats19::file_names, use.names = FALSE) | ||
if(!is.null(years)) { | ||
if(min(years) >= 2016) { | ||
result = result[!grepl(pattern = "1979", x = result)] | ||
if(min(years) >= 2018) { | ||
result = result[grepl(pattern = years, x = result)] | ||
} | ||
if(min(years) <= 2017) { | ||
result = result[!grepl(pattern = "adjust", x = result)] | ||
result = result[grepl(pattern = years, x = result)] | ||
result = result[grepl(pattern = "1979", x = result)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
|
||
# see https://github.com/ITSLeeds/stats19/issues/21 | ||
|
@@ -69,6 +70,7 @@ find_file_name = function(years = NULL, type = NULL) { | |
message("No files found. Check the stats19 website on data.gov.uk") | ||
} | ||
unique(result) | ||
} | ||
} | ||
|
||
#' Locate a file on disk | ||
|
@@ -97,11 +99,12 @@ locate_files = function(data_dir = get_data_directory(), | |
file_names = tools::file_path_sans_ext(file_names) | ||
dir_files = list.dirs(data_dir) | ||
# check is any file names match those on disk | ||
files_on_disk = vapply(file_names, function(i) any(grepl(i, dir_files)), | ||
logical(1)) | ||
if(any(files_on_disk)) { # return those on disk which match file names | ||
files_on_disk = names(files_on_disk[files_on_disk]) | ||
} | ||
files_on_disk <- list.files(dir_files, pattern = file_names, full.names = TRUE) | ||
# files_on_disk = vapply(file_names, function(i) any(grepl(i, dir_files)), | ||
# logical(1)) | ||
# if(any(files_on_disk)) { # return those on disk which match file names | ||
# files_on_disk = names(files_on_disk[files_on_disk]) | ||
# } | ||
return(files_on_disk) | ||
} | ||
|
||
|
@@ -152,6 +155,7 @@ locate_one_file = function(filename = NULL, | |
return("More than one csv file found.") | ||
return(res) | ||
} | ||
|
||
utils::globalVariables( | ||
c("stats19_variables", "stats19_schema", "skip", "accidents_sample", | ||
"accidents_sample_raw", "casualties_sample", "casualties_sample_raw", | ||
|
@@ -183,17 +187,6 @@ select_file = function(fnames) { | |
fnames[selection] | ||
} | ||
|
||
#' Get data download dir | ||
#' @examples | ||
#' # get_data_directory() | ||
get_data_directory = function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove this? It's needed in other functions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I meant to move to get.R (as it took me a while to find where it was). |
||
data_directory = Sys.getenv("STATS19_DOWNLOAD_DIRECTORY") | ||
if(data_directory != "") { | ||
return(data_directory) | ||
} | ||
tempdir() | ||
} | ||
|
||
#' Set data download dir | ||
#' | ||
#' Handy function to manage `stats19` package underlying environment | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And save for "veh" and "acc|col" so more things match.