@@ -32,12 +32,12 @@ get_directory = function() {
3232
3333# ' check and convert year argument
3434# ' @inheritParams dl_stats19
35- check_year <- function (year ) {
35+ check_year = function (year ) {
3636 if (is.null (year ) | length (year ) > 1 )
3737 stop (" Please specify a single year between 1979 and " ,
3838 format (format(Sys.Date(), " %Y" )))
39- year <- as.numeric (year )
40- current_year <- as.numeric (format(Sys.Date(), " %Y" ))
39+ year = as.numeric (year )
40+ current_year = as.numeric (format(Sys.Date(), " %Y" ))
4141 if (! year %in% 1979 : current_year )
4242 stop (" Please provide a year between 1979 and " , current_year )
4343
@@ -59,15 +59,15 @@ check_year <- function (year) {
5959# ' @export
6060find_file_name = function (years = NULL , type = NULL ) {
6161
62- years <- vapply (years , check_year , numeric (1 ))
62+ years = vapply (years , check_year , numeric (1 ))
6363 file_names_vec = unlist(stats19 :: file_names , use.names = FALSE )
64- result <- NULL
64+ result = NULL
6565 # see https://github.com/ITSLeeds/stats19/issues/21
6666 if (any (years %in% 1979 : 2004 )) {
67- result <- c (result , file_names_vec [grep (" 1979" , file_names_vec )])
67+ result = c (result , file_names_vec [grep (" 1979" , file_names_vec )])
6868 }
6969 if (is.null (years ))
70- index <- seq (file_names_vec )
70+ index = seq (file_names_vec )
7171 else
7272 index = unlist(lapply(years , function (i ) grep(i , file_names_vec ,
7373 ignore.case = TRUE )))
@@ -104,17 +104,17 @@ locate_files = function(data_dir = tempdir(),
104104 quiet = FALSE ) {
105105 stopifnot(dir.exists(data_dir ))
106106 file_names = find_file_name(years = years , type = type )
107- file_names <- tools :: file_path_sans_ext (file_names )
108- dir_files <- list.dirs (data_dir )
109- files_on_disk <- NULL
107+ file_names = tools :: file_path_sans_ext (file_names )
108+ dir_files = list.dirs (data_dir )
109+ files_on_disk = NULL
110110 # check is any file names match those on disk
111- gr <- vapply (file_names , function (i ) any (grepl (i , dir_files )),
111+ gr = vapply (file_names , function (i ) any (grepl (i , dir_files )),
112112 logical (1 ))
113113 if (any (gr )) { # return those on disk which match file names
114- gr <- names (gr [which (gr )])
115- index <- vapply (gr , function (i ) grepl (i , dir_files ),
114+ gr = names (gr [which (gr )])
115+ index = vapply (gr , function (i ) grepl (i , dir_files ),
116116 logical (length (dir_files )))
117- files_on_disk <- dir_files [index ]
117+ files_on_disk = dir_files [index ]
118118 }
119119
120120 return (files_on_disk )
@@ -131,15 +131,16 @@ locate_files = function(data_dir = tempdir(),
131131# '
132132# ' @return One of: path for one file, a message `More than one file found` or NULL
133133# ' @export
134- # ' @examples \dontrun{
134+ # ' @examples
135+ # ' \dontrun{
135136# ' locate_one_file()
136137# ' locate_one_file(filename = "Cas.csv")
137138# ' }
138139locate_one_file = function (filename = NULL ,
139140 data_dir = tempdir(),
140141 year = NULL ,
141142 type = " Accidents" ) {
142- year <- check_year (year )
143+ year = check_year (year )
143144 # see if locate_files can pin it down
144145 path = locate_files(data_dir = data_dir ,
145146 type = type ,
@@ -149,15 +150,15 @@ locate_one_file = function(filename = NULL,
149150 if (length (path ) == 0 )
150151 stop (" folder not found" ) # TODO: Delete this?
151152
152- scan1 <- function (path , type ) {
153- lf <- list.files (path , full.names = TRUE , pattern = " .csv$" )
153+ scan1 = function (path , type ) {
154+ lf = list.files (path , full.names = TRUE , pattern = " .csv$" )
154155 if (! is.null (type ))
155- lf <- lf [grep (type , lf , ignore.case = TRUE )]
156+ lf = lf [grep (type , lf , ignore.case = TRUE )]
156157 return (lf )
157158 }
158- res <- unlist (lapply (path , function (i ) scan1 (i , type )))
159+ res = unlist (lapply (path , function (i ) scan1 (i , type )))
159160 if (! is.null (filename ))
160- res <- res [grep (filename , res )]
161+ res = res [grep (filename , res )]
161162 return (res )
162163}
163164
@@ -180,7 +181,7 @@ download_and_unzip = function(exdir, zip_url, data_dir = tempdir()) {
180181 } else {
181182 utils :: download.file(zip_url , destfile = destfile )
182183 }
183- zipfiles <- file.path (destfile , utils :: unzip(destfile , list = TRUE )$ Name )
184+ zipfiles = file.path (destfile , utils :: unzip(destfile , list = TRUE )$ Name )
184185 utils :: unzip(destfile , exdir = file.path(data_dir , exdir ))
185186 return (zipfiles )
186187}
0 commit comments