-
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
changes relating to issue 237 #238
Closed
Closed
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
040b7d2
dl_stats19 returns the file path of either the downloaded file or the…
BlaiseKelly bcf1561
added additional description as well as informative messages for the …
BlaiseKelly 8284f60
Moved get_url and get_data_directory to the get module for ease of de…
BlaiseKelly c83e772
moved get_url test from test-utils.R to test-get.R
BlaiseKelly 42b549d
forgot the read function read_ve_ca.
BlaiseKelly a56e88a
IF test updated to reflect 2016 and 2017 being in 1979 file (I think)…
BlaiseKelly fd333d0
First commit
BlaiseKelly 6b7fc2b
correcting typo in title
BlaiseKelly 88a6603
first commit
BlaiseKelly b6a1b83
first commit
BlaiseKelly b8d85a0
make input reproducible
BlaiseKelly 2abe903
got rid of self contained - hopefully shows plots
BlaiseKelly c54ac56
Some errors and typos corrected
BlaiseKelly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,25 +1,4 @@ | ||
#' Convert file names to urls | ||
#' | ||
#' @details | ||
#' This function returns urls that allow data to be downloaded from the pages: | ||
#' | ||
#' https://data.dft.gov.uk/road-accidents-safety-data/RoadSafetyData_2015.zip | ||
#' | ||
#' Last updated: October 2020. | ||
#' Files available from the s3 url in the default `domain` argument. | ||
#' | ||
#' @param file_name Optional file name to add to the url returned (empty by default) | ||
#' @param domain The domain from where the data will be downloaded | ||
#' @param directory The subdirectory of the url | ||
#' @examples | ||
#' # get_url(find_file_name(1985)) | ||
get_url = function(file_name = "", | ||
domain = "https://data.dft.gov.uk", | ||
directory = "road-accidents-safety-data" | ||
) { | ||
path = file.path(domain, directory, file_name) | ||
path | ||
} | ||
|
||
|
||
# current_year() | ||
current_year = function() as.integer(format(format(Sys.Date(), "%Y"))) | ||
|
@@ -47,7 +26,7 @@ find_file_name = function(years = NULL, type = NULL) { | |
result = result[!grepl(pattern = "1979", x = result)] | ||
} | ||
result = result[!grepl(pattern = "adjust", x = result)] | ||
result = result[grepl(pattern = years, x = result)] | ||
result = result[grepl(pattern = "1979", x = result)] | ||
} | ||
|
||
# see https://github.com/ITSLeeds/stats19/issues/21 | ||
|
@@ -97,11 +76,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 +132,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 +164,6 @@ select_file = function(fnames) { | |
fnames[selection] | ||
} | ||
|
||
#' Get data download dir | ||
#' @examples | ||
#' # get_data_directory() | ||
get_data_directory = function() { | ||
data_directory = Sys.getenv("STATS19_DOWNLOAD_DIRECTORY") | ||
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. +1 to moving everything into a more accessible place. |
||
if(data_directory != "") { | ||
return(data_directory) | ||
} | ||
tempdir() | ||
} | ||
|
||
#' Set data download dir | ||
#' | ||
#' Handy function to manage `stats19` package underlying environment | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
+1 to that, although will it still work for non 1979 (all) years? I guess so but would need to test..