Skip to content

Commit 327e436

Browse files
committed
style pkg with styler::equals_style
1 parent 8901c9d commit 327e436

5 files changed

Lines changed: 33 additions & 32 deletions

File tree

R/data.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,3 @@ NULL
6262
# The raw csv file is stored as `ac_2005_2014_100.csv`
6363
# @rdname ac_2005_2014_100
6464
# "ac_2005_2014_100"
65-

R/dl_stats19.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#' @examples
2222
#' \dontrun{
2323
#' dl_stats19(year = 2017) # interactively select files...
24-
#'
24+
#'
2525
#' # now you can read-in the data
2626
#' dl_stats19(year = 2009)
2727
#' }
@@ -31,7 +31,7 @@ dl_stats19 = function(file_name = NULL,
3131
data_dir = tempdir()) {
3232

3333
if (!is.null (year))
34-
year <- check_year (year)
34+
year = check_year (year)
3535
else if (is.null (file_name))
3636
stop("Either file_name or year must be specified")
3737
type = convert_type_param(type)

R/format.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ format_vehicles = function(x, factorize = FALSE) {
143143
#' such as spaces and `-` are returned.
144144
#' @param column_names Column names to be cleaned
145145
#' @export
146-
#' @examples \dontrun{
146+
#' @examples
147+
#' \dontrun{
147148
#' crashes_raw = read_accidents()
148149
#' column_names = names(crashes_raw)
149150
#' column_names
@@ -169,7 +170,8 @@ format_column_names = function(column_names) {
169170
#' @inheritParams read_accidents
170171
#' @param sheet integer to be added if you want to download a single sheet
171172
#' @export
172-
#' @examples \dontrun{
173+
#' @examples
174+
#' \dontrun{
173175
#' stats19_schema = read_schema()
174176
#' }
175177
read_schema = function(
@@ -353,4 +355,3 @@ format_sf = function(x, lonlat = FALSE) {
353355
}
354356
x_sf
355357
}
356-

R/read_stats19.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ read_accidents = function(filename = "",
2121
year = NULL) {
2222
# check inputs
2323
if (!is.null (year))
24-
year <- check_year (year)
24+
year = check_year (year)
2525
path = check_input_file(
2626
filename = filename,
2727
type = "accidents",
@@ -68,7 +68,7 @@ read_vehicles = function(filename = NULL,
6868
data_dir = tempdir(),
6969
year = NULL) {
7070
# check inputs
71-
year <- check_year (year)
71+
year = check_year (year)
7272
path = check_input_file(
7373
filename = filename,
7474
type = "vehicles",
@@ -102,7 +102,7 @@ read_casualties = function(filename = NULL,
102102
year = NULL) {
103103

104104
# check inputs
105-
year <- check_year (year)
105+
year = check_year (year)
106106
path = check_input_file(
107107
filename = filename,
108108
type = "casualties",
@@ -129,7 +129,7 @@ check_input_file = function(filename = NULL,
129129
type = NULL,
130130
data_dir = NULL,
131131
year = NULL) {
132-
year <- check_year (year)
132+
year = check_year (year)
133133
path = locate_one_file(
134134
type = type,
135135
filename = filename,

R/utils.R

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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
6060
find_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
#' }
138139
locate_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

Comments
 (0)