Skip to content

Commit 34baa11

Browse files
averissimom7pr
andauthored
Removes return call if it is the last expression (#177)
# Pull Request Part of #172 Simple change, but I created PR since it touches code #### Changes description - Removes `return(...)` call if it is the last expression - Per NEST guidelines --------- Co-authored-by: m7pr <marcin.kosinski.mk1@roche.com>
1 parent e1ac439 commit 34baa11

13 files changed

+92
-91
lines changed

R/choices_labeled.R

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,15 @@ choices_labeled <- function(choices, labels, subset = NULL, types = NULL) {
106106
combined_labels <- combined_labels[ord]
107107
types <- types[ord]
108108
}
109-
choices <- structure(
109+
110+
structure(
110111
choices,
111112
names = combined_labels,
112113
raw_labels = raw_labels,
113114
combined_labels = combined_labels,
114115
class = c("choices_labeled", "character"),
115116
types = types
116117
)
117-
118-
return(choices)
119118
}
120119

121120
#' Wrapper on [choices_labeled] to label variables basing on existing labels in data
@@ -164,7 +163,7 @@ choices_labeled <- function(choices, labels, subset = NULL, types = NULL) {
164163
#' # functional subset (with delayed data) - return only factor variables
165164
#' variable_choices("ADRS", subset = function(data) {
166165
#' idx <- vapply(data, is.factor, logical(1))
167-
#' return(names(data)[idx])
166+
#' names(data)[idx]
168167
#' })
169168
#' @export
170169
#'
@@ -222,7 +221,7 @@ variable_choices.data.frame <- function(data, subset = NULL, fill = TRUE, key =
222221
subset <- unique(subset)
223222
}
224223

225-
res <- if ("" %in% subset) {
224+
if ("" %in% subset) {
226225
choices_labeled(
227226
choices = c("", names(data)),
228227
labels = c("", unname(teal.data::col_labels(data, fill = fill))),
@@ -237,8 +236,6 @@ variable_choices.data.frame <- function(data, subset = NULL, fill = TRUE, key =
237236
types = var_types
238237
)
239238
}
240-
241-
return(res)
242239
}
243240

244241
#' Wrapper on [choices_labeled] to label variable values basing on other variable values
@@ -276,7 +273,7 @@ variable_choices.data.frame <- function(data, subset = NULL, fill = TRUE, key =
276273
#'
277274
#' # functional subset
278275
#' value_choices(ADRS, "PARAMCD", "PARAM", subset = function(data) {
279-
#' return(levels(data$PARAMCD)[1:2])
276+
#' levels(data$PARAMCD)[1:2]
280277
#' })
281278
#' @export
282279
#'
@@ -302,7 +299,7 @@ value_choices.character <- function(data,
302299
var_label = NULL,
303300
subset = NULL,
304301
sep = " - ") {
305-
out <- structure(
302+
structure(
306303
list(
307304
data = data,
308305
var_choices = var_choices,
@@ -312,7 +309,6 @@ value_choices.character <- function(data,
312309
),
313310
class = c("delayed_value_choices", "delayed_data", "choices_labeled")
314311
)
315-
return(out)
316312
}
317313

318314
#' @rdname value_choices
@@ -373,7 +369,7 @@ value_choices.data.frame <- function(data, # nolint
373369
attr(res, "sep") <- sep
374370
attr(res, "var_choices") <- var_choices
375371
attr(res, "var_label") <- var_label
376-
return(res)
372+
res
377373
}
378374

379375
#' Print choices_labeled object
@@ -397,5 +393,5 @@ print.choices_labeled <- function(x, ...) {
397393
sep = "\n"
398394
)
399395

400-
return(invisible(x))
396+
invisible(x)
401397
}

R/choices_selected.R

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ no_select_keyword <- "-- no selection --"
104104
#' # with delayed data loading
105105
#' choices_selected(variable_choices("ADSL", subset = function(data) {
106106
#' idx <- vapply(data, is.factor, logical(1))
107-
#' return(names(data)[idx])
107+
#' names(data)[idx]
108108
#' }))
109109
#'
110110
#' cs <- choices_selected(
@@ -142,11 +142,12 @@ choices_selected <- function(choices,
142142
}
143143

144144
if (inherits(choices, "delayed_data")) {
145-
out <- structure(
146-
list(choices = choices, selected = selected, keep_order = keep_order, fixed = fixed),
147-
class = c("delayed_choices_selected", "delayed_data", "choices_selected")
145+
return(
146+
structure(
147+
list(choices = choices, selected = selected, keep_order = keep_order, fixed = fixed),
148+
class = c("delayed_choices_selected", "delayed_data", "choices_selected")
149+
)
148150
)
149-
return(out)
150151
}
151152

152153
if (!is.null(choices) && no_select_keyword %in% choices) {
@@ -254,8 +255,7 @@ vector_reorder <- function(vec, idx) {
254255
}
255256

256257
attributes(vec) <- vec_attrs
257-
258-
return(vec)
258+
vec
259259
}
260260

261261
vector_pop <- function(vec, idx) {
@@ -277,7 +277,7 @@ vector_pop <- function(vec, idx) {
277277

278278
vec <- vec[-idx]
279279
attributes(vec) <- vec_attrs
280-
return(vec)
280+
vec
281281
}
282282

283283
vector_remove_dups <- function(vec) {
@@ -286,12 +286,12 @@ vector_remove_dups <- function(vec) {
286286
idx <- which(duplicated(vec))
287287

288288
if (length(idx) == 0) {
289-
return(vec)
289+
vec
290290
} else if (is.null(attributes(vec))) {
291-
return(unique(vec))
291+
unique(vec)
292292
} else if (identical(names(attributes(vec)), "names")) {
293-
return(vec[-idx])
293+
vec[-idx]
294294
} else {
295-
return(vector_pop(vec, idx))
295+
vector_pop(vec, idx)
296296
}
297297
}

R/filter_spec.R

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ filter_spec_internal.delayed_data <- function(vars_choices, # nolint
332332
checkmate::check_class(selected, "all_choices")
333333
)
334334

335-
out <- structure(
335+
structure(
336336
list(
337337
vars_choices = vars_choices,
338338
vars_selected = vars_selected,
@@ -355,7 +355,6 @@ filter_spec_internal.delayed_data <- function(vars_choices, # nolint
355355
"delayed_data"
356356
)
357357
)
358-
return(out)
359358
}
360359

361360
#' @rdname filter_spec_internal
@@ -410,23 +409,23 @@ filter_spec_internal.default <- function(vars_choices,
410409
checkmate::assert_subset(selected, choices)
411410
}
412411

413-
res <- list(
414-
vars_choices = vars_choices,
415-
vars_selected = vars_selected,
416-
vars_label = vars_label,
417-
vars_fixed = vars_fixed,
418-
vars_multiple = vars_multiple,
419-
choices = choices,
420-
selected = selected,
421-
label = label,
422-
multiple = multiple,
423-
fixed = fixed,
424-
sep = sep,
425-
drop_keys = drop_keys,
426-
dataname = dataname, # modified by data_extract_spec
427-
initialized = initialized
412+
structure(
413+
list(
414+
vars_choices = vars_choices,
415+
vars_selected = vars_selected,
416+
vars_label = vars_label,
417+
vars_fixed = vars_fixed,
418+
vars_multiple = vars_multiple,
419+
choices = choices,
420+
selected = selected,
421+
label = label,
422+
multiple = multiple,
423+
fixed = fixed,
424+
sep = sep,
425+
drop_keys = drop_keys,
426+
dataname = dataname, # modified by data_extract_spec
427+
initialized = initialized
428+
),
429+
class = "filter_spec"
428430
)
429-
class(res) <- "filter_spec"
430-
431-
return(res)
432431
}

R/get_dplyr_call.R

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,10 @@ get_dplyr_call <- function(selector_list,
241241
NULL
242242
}
243243

244-
final_call <- Reduce(
244+
Reduce(
245245
function(x, y) call("%>%", x, y),
246246
Filter(function(x) !is.null(x), c(dataname_filtered, filter_call, select_call, rename_call, reshape_call))
247247
)
248-
249-
return(final_call)
250248
}
251249

252250
#' Parse `dplyr` select call
@@ -639,12 +637,10 @@ get_reshape_unite_vals <- function(selector) {
639637
)
640638
unite_cols_vals <- unite_cols_vals[vapply(unite_cols_vals, length, integer(1)) > 0]
641639

642-
res <- if (length(unite_cols_vals) > 0) {
640+
if (length(unite_cols_vals) > 0) {
643641
grid <- do.call(expand.grid, args = list(unite_cols_vals, stringsAsFactors = FALSE))
644642
apply(grid, 1, paste, collapse = "_")
645643
} else {
646644
character(0)
647645
}
648-
649-
res
650646
}

R/get_merge_call.R

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ get_merge_call <- function(selector_list,
112112
anl_merge_call_i
113113
)
114114
}
115-
return(anl_merge_calls)
115+
116+
anl_merge_calls
116117
}
117118

118119
#' Gets merge key pair list from keys list
@@ -443,7 +444,7 @@ get_anl_relabel_call <- function(columns_source, datasets, anl_name = "ANL") {
443444
relabel_call
444445
)
445446

446-
return(relabel_and_assign_call)
447+
relabel_and_assign_call
447448
}
448449

449450
#' Create relabel call from named character
@@ -482,12 +483,10 @@ get_relabel_call <- function(labels) {
482483
labels <- labels[!duplicated(names(labels))]
483484
labels <- labels[!is.na(labels)]
484485

485-
return(
486-
as.call(
487-
append(
488-
quote(teal.data::col_relabel),
489-
labels
490-
)
486+
as.call(
487+
append(
488+
quote(teal.data::col_relabel),
489+
labels
491490
)
492491
)
493492
}
@@ -517,7 +516,7 @@ get_relabel_cols <- function(columns_source, dplyr_call_data) {
517516
return(NULL)
518517
}
519518
attr(column_source, "dataname") <- dataname
520-
return(column_source)
519+
column_source
521520
}
522521
)
523522
}

R/include_css_js.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ include_css_files <- function(pattern = "*") {
1616
system.file("css", package = "teal.transform", mustWork = TRUE),
1717
pattern = pattern, full.names = TRUE
1818
)
19-
return(singleton(lapply(css_files, includeCSS)))
19+
singleton(lapply(css_files, includeCSS))
2020
}

R/merge_datasets.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ merge_datasets <- function(selector_list, datasets, join_keys, merge_function =
170170
filter_info = filter_info
171171
)
172172
logger::log_trace("merge_datasets merge code executed resulting in { anl_name } dataset.")
173-
return(res)
173+
res
174174
}
175175

176176
#' Merge selectors when `dataname`, `reshape`, `filters` and `keys` entries are identical
@@ -259,7 +259,7 @@ merge_selectors <- function(selector_list) {
259259
}
260260
}
261261

262-
return(list(res_list, res_map_id))
262+
list(res_list, res_map_id)
263263
}
264264

265265

0 commit comments

Comments
 (0)