Skip to content

Commit e74a2aa

Browse files
author
kalibera
committed
Do not copy in na.omit.data.frame and na.exclude.data.frame when there are
no NAs (PR#16714). git-svn-id: https://svn.r-project.org/R/trunk@88495 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent ca8ec36 commit e74a2aa

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/library/stats/R/nafns.R

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# File src/library/stats/R/nafns.R
22
# Part of the R package, https://www.R-project.org
33
#
4-
# Copyright (C) 1995-2018 The R Core Team
4+
# Copyright (C) 1995-2025 The R Core Team
55
#
66
# This program is free software; you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -75,14 +75,15 @@ na.omit.data.frame <- function(object, ...)
7575
for(ii in 1L:d[2L])
7676
omit <- omit | x[, ii]
7777
}
78-
xx <- object[!omit, , drop = FALSE]
7978
if (any(omit > 0L)) {
79+
xx <- object[!omit, , drop = FALSE]
8080
temp <- setNames(seq(omit)[omit],
8181
attr(object, "row.names")[omit])
8282
attr(temp, "class") <- "omit"
8383
attr(xx, "na.action") <- temp
84+
object <- xx
8485
}
85-
xx
86+
object
8687
}
8788

8889
na.exclude <- function(object, ...) UseMethod("na.exclude")
@@ -129,14 +130,15 @@ na.exclude.data.frame <- function(object, ...)
129130
for(ii in 1L:d[2L])
130131
omit <- omit | x[, ii]
131132
}
132-
xx <- object[!omit, , drop = FALSE]
133133
if (any(omit > 0L)) {
134+
xx <- object[!omit, , drop = FALSE]
134135
temp <- setNames(seq(omit)[omit],
135136
attr(object, "row.names")[omit])
136137
attr(temp, "class") <- "exclude"
137138
attr(xx, "na.action") <- temp
139+
object <- xx
138140
}
139-
xx
141+
object
140142
}
141143

142144
naresid <- function(omit, x, ...) UseMethod("naresid")

0 commit comments

Comments
 (0)