Skip to content

Commit 7bd1c2d

Browse files
committed
simplify get_warnings
1 parent 4c7fa7a commit 7bd1c2d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

R/qenv-get_warnings.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ setGeneric("get_warnings", function(object) {
3434

3535
setMethod("get_warnings", signature = c("qenv"), function(object) {
3636
warnings <- lapply(object@code, "attr", "warning")
37-
code <- object@code[unlist(lapply(warnings, Negate(is.null)))]
37+
idx_warn <- which(sapply(warnings, Negate(is.null)))
38+
warnings <- warnings[idx_warn]
39+
code <- object@code[idx_warn]
3840
if (length(unlist(warnings)) == 0) {
3941
return(NULL)
4042
}
@@ -46,8 +48,8 @@ setMethod("get_warnings", signature = c("qenv"), function(object) {
4648
}
4749
sprintf("%swhen running code:\n%s", warn, paste(lang2calls(expr), collapse = "\n"))
4850
},
49-
warn = as.list(unlist(warnings)),
50-
expr = as.list(unlist(code))
51+
warn = warnings,
52+
expr = code
5153
)
5254
lines <- Filter(Negate(is.null), lines)
5355

0 commit comments

Comments
 (0)