Skip to content

Commit 3025256

Browse files
author
smeyer
committed
summary(): "NA's" -> "NAs" (PR#18948)
git-svn-id: https://svn.r-project.org/R/trunk@89306 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent ddf69c2 commit 3025256

File tree

7 files changed

+55
-52
lines changed

7 files changed

+55
-52
lines changed

doc/NEWS.Rd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@
520520

521521
\item \code{pretty(ch)} again correctly works with \code{ch} a
522522
character vector of numbers.
523+
524+
\item The default \code{summary()} and its factor method now
525+
label missing values \samp{NAs} rather than \samp{NA's},
526+
fixing a decades-old grammatical faux pas inherited from S
527+
(\PR{16348} and \PR{18948}).
523528
}
524529
}
525530
}

src/library/base/R/dates.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ print.Date <- function(x, max = NULL, ...)
136136
summary.Date <- function(object, digits = 12L, ...)
137137
{
138138
x <- summary.default(unclass(object), digits = digits, ...)
139-
if(m <- match("NA's", names(x), 0L)) {
139+
if(m <- match("NAs", names(x), 0L)) {
140140
NAs <- as.integer(x[m])
141141
x <- x[-m]
142142
attr(x, "NAs") <- NAs

src/library/base/R/datetime.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ print.POSIXlt <- function(x, tz = "", usetz = TRUE, max = NULL,
459459
summary.POSIXct <- function(object, digits = 15L, ...)
460460
{
461461
x <- summary.default(unclass(object), digits = digits, ...)
462-
if(m <- match("NA's", names(x), 0L)) {
462+
if(m <- match("NAs", names(x), 0L)) {
463463
NAs <- as.integer(x[m])
464464
x <- x[-m]
465465
attr(x, "NAs") <- NAs
@@ -950,7 +950,7 @@ summary.difftime <-
950950
function(object, digits = getOption("digits"), ...)
951951
{
952952
x <- summary.default(unclass(object), digits = digits, ...)
953-
if(m <- match("NA's", names(x), 0L)) {
953+
if(m <- match("NAs", names(x), 0L)) {
954954
NAs <- as.integer(x[m])
955955
x <- x[-m]
956956
attr(x, "NAs") <- NAs

src/library/base/R/summary.R

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# File src/library/base/R/summary.R
22
# Part of the R package, https://www.R-project.org
33
#
4-
# Copyright (C) 1995-2025 The R Core Team
4+
# Copyright (C) 1995-2026 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
@@ -29,22 +29,20 @@ summary.default <- function(object, ..., digits, quantile.type = 7)
2929
return(summary.matrix(object, digits = digits, quantile.type=quantile.type, ...))
3030
}
3131

32-
value <- if(is.logical(object)) # scalar or array!
33-
c(Mode = "logical",
34-
{tb <- table(object, exclude = NULL, useNA = "ifany") # incl. NA s
35-
if(!is.null(n <- dimnames(tb)[[1L]]) && any(iN <- is.na(n)))
36-
dimnames(tb)[[1L]][iN] <- "NA's"
37-
tb
38-
})
39-
else if(is.numeric(object)) {
32+
value <- if(is.logical(object)) { # scalar or array!
33+
tb <- table(object, exclude = NULL, useNA = "ifany") # incl. NAs
34+
if(!is.null(n <- dimnames(tb)[[1L]]) && any(iN <- is.na(n)))
35+
dimnames(tb)[[1L]][iN] <- "NAs"
36+
c(Mode = "logical", tb)
37+
} else if(is.numeric(object)) {
4038
nas <- is.na(object)
4139
object <- object[!nas]
4240
qq <- stats::quantile(object, names = FALSE, type = quantile.type)
4341
qq <- c(qq[1L:3L], mean(object), qq[4L:5L])
4442
if(!missing(digits)) qq <- signif(qq, digits)
4543
names(qq) <- c("Min.", "1st Qu.", "Median", "Mean", "3rd Qu.", "Max.")
4644
if(any(nas))
47-
c(qq, "NA's" = sum(nas))
45+
c(qq, "NAs" = sum(nas))
4846
else qq
4947
} else if(is.recursive(object) && !is.language(object) &&
5048
(n <- length(object))) { # do not allow long dims
@@ -75,12 +73,12 @@ format.summaryDefault <- function(x, digits = max(3L, getOption("digits") - 3L),
7573
xx[finite] <- zapsmall(x[finite], digits = digs + zdigits)
7674
}
7775
class(xx) <- class(x)[-1]
78-
m <- match("NA's", names(x), 0)
76+
m <- match("NAs", names(x), 0)
7977
if((iD <- inherits(x, "Date")) | (iP <- inherits(x, "POSIXct")) || inherits(x, "difftime")) {
8078
c(format(xx, digits = if(iP) 0L else digits),
81-
"NA's" = if(length(a <- attr(x, "NAs"))) as.character(a))
79+
"NAs" = if(length(a <- attr(x, "NAs"))) as.character(a))
8280
} else if(m && !is.character(x))
83-
c(format(xx[-m], digits=digits, ...), "NA's" = as.character(xx[m]))
81+
c(format(xx[-m], digits=digits, ...), "NAs" = as.character(xx[m]))
8482
else format(xx, digits=digits, ...)
8583
}
8684

@@ -102,11 +100,11 @@ print.summaryDefault <- function(x, digits = max(3L, getOption("digits") - 3L),
102100
if(no.q) quote <- FALSE
103101
}
104102
xx <- c(format(xx, digits = digits, with.units = FALSE),
105-
"NA's" = if(length(a <- attr(x, "NAs"))) as.character(a))
103+
"NAs" = if(length(a <- attr(x, "NAs"))) as.character(a))
106104
print(xx, quote = quote, ...)
107105
return(invisible(x))
108-
} else if((m <- match("NA's", names(xx), 0L)) && !is.character(x))
109-
xx <- c(format(xx[-m], digits=digits), "NA's" = as.character(xx[m]))
106+
} else if((m <- match("NAs", names(xx), 0L)) && !is.character(x))
107+
xx <- c(format(xx[-m], digits=digits), "NAs" = as.character(xx[m]))
110108
print.table(xx, digits=digits, ...)
111109
invisible(x)
112110
}
@@ -124,7 +122,7 @@ summary.factor <- function(object, maxsum = 100L, ...)
124122
o <- sort.list(tt, decreasing = TRUE)
125123
tt <- c(tt[o[ - drop]], "(Other)" = sum(tt[o[drop]]))
126124
}
127-
if(ana) c(tt, "NA's" = sum(nas)) else tt
125+
if(ana) c(tt, "NAs" = sum(nas)) else tt
128126
}
129127

130128
summary.matrix <- function(object, ...) {

tests/Examples/datasets-Ex.Rout.save

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
R Under development (unstable) (2025-08-11 r88568) -- "Unsuffered Consequences"
3-
Copyright (C) 2025 The R Foundation for Statistical Computing
2+
R Under development (unstable) (2026-01-16 r89305) -- "Unsuffered Consequences"
3+
Copyright (C) 2026 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

66
R is free software and comes with ABSOLUTELY NO WARRANTY.
@@ -1808,7 +1808,7 @@ x4 0.4999091 0.1178189 4.243028 0.002164602
18081808
Mean :14.74 Mean :6.084 112 : 3 Mean : 45.60
18091809
3rd Qu.:20.00 3rd Qu.:6.600 135 : 3 3rd Qu.: 47.55
18101810
Max. :23.00 Max. :7.700 (Other):147 Max. :370.00
1811-
NA's : 16
1811+
NAs : 16
18121812
accel
18131813
Min. :0.00300
18141814
1st Qu.:0.04425
@@ -2994,15 +2994,15 @@ Warning: not plotting observations with leverage one:
29942994
Mean :43.92 Mean :17.15
29952995
3rd Qu.:48.50 3rd Qu.:18.70
29962996
Max. :59.60 Max. :21.50
2997-
NA's :2 NA's :2
2997+
NAs :2 NAs :2
29982998
flipper_len body_mass sex year
29992999
Min. :172.0 Min. :2700 female:165 Min. :2007
30003000
1st Qu.:190.0 1st Qu.:3550 male :168 1st Qu.:2007
3001-
Median :197.0 Median :4050 NA's : 11 Median :2008
3001+
Median :197.0 Median :4050 NAs : 11 Median :2008
30023002
Mean :200.9 Mean :4202 Mean :2008
30033003
3rd Qu.:213.0 3rd Qu.:4750 3rd Qu.:2009
30043004
Max. :231.0 Max. :6300 Max. :2009
3005-
NA's :2 NA's :2
3005+
NAs :2 NAs :2
30063006
> summary(penguins_raw) # not useful for character vectors
30073007
studyName Sample Number Species Region
30083008
Length:344 Min. : 1.00 Length:344 Length:344
@@ -3027,15 +3027,15 @@ Warning: not plotting observations with leverage one:
30273027
Mean :2008-11-27 Mean :43.92 Mean :17.15 Mean :200.9
30283028
3rd Qu.:2009-11-16 3rd Qu.:48.50 3rd Qu.:18.70 3rd Qu.:213.0
30293029
Max. :2009-12-01 Max. :59.60 Max. :21.50 Max. :231.0
3030-
NA's :2 NA's :2 NA's :2
3030+
NAs :2 NAs :2 NAs :2
30313031
Body Mass (g) Sex Delta 15 N (o/oo) Delta 13 C (o/oo)
30323032
Min. :2700 Length:344 Min. : 7.632 Min. :-27.02
30333033
1st Qu.:3550 Class :character 1st Qu.: 8.300 1st Qu.:-26.32
30343034
Median :4050 Mode :character Median : 8.652 Median :-25.83
30353035
Mean :4202 Mean : 8.733 Mean :-25.69
30363036
3rd Qu.:4750 3rd Qu.: 9.172 3rd Qu.:-25.06
30373037
Max. :6300 Max. :10.025 Max. :-23.79
3038-
NA's :2 NA's :14 NA's :13
3038+
NAs :2 NAs :14 NAs :13
30393039
Comments
30403040
Length:344
30413041
Class :character
@@ -3073,23 +3073,23 @@ Warning: not plotting observations with leverage one:
30733073
Mean :2008-11-27 Mean :43.92 Mean :17.15
30743074
3rd Qu.:2009-11-16 3rd Qu.:48.50 3rd Qu.:18.70
30753075
Max. :2009-12-01 Max. :59.60 Max. :21.50
3076-
NA's :2 NA's :2
3076+
NAs :2 NAs :2
30773077
Flipper Length (mm) Body Mass (g) Sex Delta 15 N (o/oo)
30783078
Min. :172.0 Min. :2700 FEMALE:165 Min. : 7.632
30793079
1st Qu.:190.0 1st Qu.:3550 MALE :168 1st Qu.: 8.300
3080-
Median :197.0 Median :4050 NA's : 11 Median : 8.652
3080+
Median :197.0 Median :4050 NAs : 11 Median : 8.652
30813081
Mean :200.9 Mean :4202 Mean : 8.733
30823082
3rd Qu.:213.0 3rd Qu.:4750 3rd Qu.: 9.172
30833083
Max. :231.0 Max. :6300 Max. :10.025
3084-
NA's :2 NA's :2 NA's :14
3084+
NAs :2 NAs :2 NAs :14
30853085
Delta 13 C (o/oo) Comments
30863086
Min. :-27.02 Nest never observed with full clutch.: 34
30873087
1st Qu.:-26.32 Not enough blood for isotopes. : 7
30883088
Median :-25.83 Sexing primers did not amplify. : 4
30893089
Mean :-25.69 No blood sample obtained for sexing. : 2
30903090
3rd Qu.:-25.06 No blood sample obtained. : 2
30913091
Max. :-23.79 (Other) : 5
3092-
NA's :13 NA's :290
3092+
NAs :13 NAs :290
30933093
>
30943094
> ## visualise distribution across factors
30953095
> plot(island ~ species, data = penguins)

tests/print-tests.Rout.save

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
R Under development (unstable) (2025-02-20 r87768) -- "Unsuffered Consequences"
3-
Copyright (C) 2025 The R Foundation for Statistical Computing
2+
R Under development (unstable) (2026-01-16 r89305) -- "Unsuffered Consequences"
3+
Copyright (C) 2026 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

66
R is free software and comes with ABSOLUTELY NO WARRANTY.
@@ -451,7 +451,7 @@ b 1.2+11i 2.4+23.141593i
451451
Mean :14.74 Mean :6.084 112 : 3 Mean : 45.60 Mean :0.15422
452452
3rd Qu.:20.00 3rd Qu.:6.600 135 : 3 3rd Qu.: 47.55 3rd Qu.:0.21925
453453
Max. :23.00 Max. :7.700 (Other):147 Max. :370.00 Max. :0.81000
454-
NA's : 16
454+
NAs : 16
455455
> lst <- levels(attenu$station)
456456
> levels(attenu$station)[lst == "117"] <- paste(rep(letters,3),collapse="")
457457
> summary(attenu) # {2 + one long + 2 } variables
@@ -470,7 +470,7 @@ b 1.2+11i 2.4+23.141593i
470470
112 : 3
471471
135 : 3
472472
(Other) :147
473-
NA's : 16
473+
NAs : 16
474474
dist accel
475475
Min. : 0.50 Min. :0.00300
476476
1st Qu.: 11.32 1st Qu.:0.04425

tests/reg-tests-2.Rout.save

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
R Under development (unstable) (2025-12-11 r89141) -- "Unsuffered Consequences"
3-
Copyright (C) 2025 The R Foundation for Statistical Computing
2+
R Under development (unstable) (2026-01-16 r89305) -- "Unsuffered Consequences"
3+
Copyright (C) 2026 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

66
R is free software and comes with ABSOLUTELY NO WARRANTY.
@@ -934,7 +934,7 @@ $B$subset
934934
Mean :14.74 Mean :6.084 112 : 3 Mean : 45.60
935935
3rd Qu.:20.00 3rd Qu.:6.600 135 : 3 3rd Qu.: 47.55
936936
Max. :23.00 Max. :7.700 (Other):147 Max. :370.00
937-
NA's : 16
937+
NAs : 16
938938
accel
939939
Min. :0.00300
940940
1st Qu.:0.04425
@@ -951,7 +951,7 @@ $B$subset
951951
Mean :14.742 Mean :6.0841 112 : 3 Mean : 45.603
952952
3rd Qu.:20.000 3rd Qu.:6.6000 135 : 3 3rd Qu.: 47.550
953953
Max. :23.000 Max. :7.7000 (Other):147 Max. :370.000
954-
NA's : 16
954+
NAs : 16
955955
accel
956956
Min. :0.00300
957957
1st Qu.:0.04425
@@ -968,7 +968,7 @@ $B$subset
968968
Mean :14.742 Mean :6.0841 Mean : 56.928 Mean : 45.603
969969
3rd Qu.:20.000 3rd Qu.:6.6000 3rd Qu.: 86.750 3rd Qu.: 47.550
970970
Max. :23.000 Max. :7.7000 Max. :117.000 Max. :370.000
971-
NA's :16
971+
NAs :16
972972
accel
973973
Min. :0.00300
974974
1st Qu.:0.04425
@@ -6393,7 +6393,7 @@ function(given = NULL) {
63936393
if (is.null(given)) callObj$default <- TRUE
63946394
callObj
63956395
}
6396-
<bytecode: 0x6176199e3d98>
6396+
<bytecode: 0x5ab0d0f733e8>
63976397
> print(foo, useSource = FALSE)
63986398
function (given = NULL)
63996399
{
@@ -6404,7 +6404,7 @@ function (given = NULL)
64046404
callObj$default <- TRUE
64056405
callObj
64066406
}
6407-
<bytecode: 0x6176199e3d98>
6407+
<bytecode: 0x5ab0d0f733e8>
64086408
> attr(foo, "srcref") <- NULL
64096409
> foo
64106410
function (given = NULL)
@@ -6416,7 +6416,7 @@ function (given = NULL)
64166416
callObj$default <- TRUE
64176417
callObj
64186418
}
6419-
<bytecode: 0x6176199e3d98>
6419+
<bytecode: 0x5ab0d0f733e8>
64206420
> (f <- structure(function(){}, note = "just a note",
64216421
+ yada = function() "not the same"))
64226422
function(){}
@@ -7898,7 +7898,7 @@ list(one = 1, two = )
78987898
> summary(x.Date)
78997899
Min. 1st Qu. Median Mean 3rd Qu. Max.
79007900
"1881-09-24" "1902-12-04" "1920-09-10" "1923-04-12" "1941-01-17" "1969-12-28"
7901-
NA's
7901+
NAs
79027902
"3"
79037903
> DF.Dates <- data.frame(c1 = x.Date)
79047904
> summary(DF.Dates) ## NA's missing from output :
@@ -7909,7 +7909,7 @@ list(one = 1, two = )
79097909
Mean :1923-04-12
79107910
3rd Qu.:1941-01-17
79117911
Max. :1969-12-28
7912-
NA's :3
7912+
NAs :3
79137913
> DF.Dates$x1 <- 1:7
79147914
> summary(DF.Dates) ## NA's still missing
79157915
c1 x1
@@ -7919,7 +7919,7 @@ list(one = 1, two = )
79197919
Mean :1923-04-12 Mean :4.0
79207920
3rd Qu.:1941-01-17 3rd Qu.:5.5
79217921
Max. :1969-12-28 Max. :7.0
7922-
NA's :3
7922+
NAs :3
79237923
> DF.Dates$x2 <- c(1:6, NA)
79247924
> ## now, NA's show fine:
79257925
> summary(DF.Dates)
@@ -7930,7 +7930,7 @@ list(one = 1, two = )
79307930
Mean :1923-04-12 Mean :4.0 Mean :3.50
79317931
3rd Qu.:1941-01-17 3rd Qu.:5.5 3rd Qu.:4.75
79327932
Max. :1969-12-28 Max. :7.0 Max. :6.00
7933-
NA's :3 NA's :1
7933+
NAs :3 NAs :1
79347934
> ## 2 of 4 summary(.) above did not show NA's in R <= 3.2.3
79357935
>
79367936
>
@@ -7951,7 +7951,7 @@ list(one = 1, two = )
79517951
> ## summary(<logical>) working via table():
79527952
> logi <- c(NA, logical(3), NA, !logical(2), NA)
79537953
> summary(logi)
7954-
Mode FALSE TRUE NA's
7954+
Mode FALSE TRUE NAs
79557955
logical 3 2 3
79567956
> summary(logi[!is.na(logi)])
79577957
Mode FALSE TRUE
@@ -7962,7 +7962,7 @@ logical 1
79627962
> ## was always showing counts for NA's even when 0 in 2.8.0 <= R <= 3.3.1
79637963
> ii <- as.integer(logi)
79647964
> summary(ii)
7965-
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
7965+
Min. 1st Qu. Median Mean 3rd Qu. Max. NAs
79667966
0.0 0.0 0.0 0.4 1.0 1.0 3
79677967
> summary(ii[!is.na(ii)])
79687968
Min. 1st Qu. Median Mean 3rd Qu. Max.
@@ -8369,7 +8369,7 @@ Error in f() : argument is missing, with no default
83698369
> withAutoprint({ show.srcref() })
83708370
language show.srcref()
83718371
- attr(*, "srcref")= 'srcref' int [1:8] 1 21 1 33 21 33 3 3
8372-
..- attr(*, "srcfile")=Classes 'srcfilealias', 'srcfile' <environment: 0x61761aa14088>
8372+
..- attr(*, "srcfile")=Classes 'srcfilealias', 'srcfile' <environment: 0x5ab0ce13c1d8>
83738373
> ## no attr(*, "src..") in R <= 4.3.1
83748374
> ##
83758375
> withAutoprint({
@@ -8382,5 +8382,5 @@ Error in f() : argument is missing, with no default
83828382
>
83838383
> # ----- Last line -------------
83848384
> cat('Time elapsed: ', proc.time(),'\n')
8385-
Time elapsed: 0.735 0.05 0.793 0.001 0.001
8385+
Time elapsed: 1.162 0.101 1.266 0 0.002
83868386
>

0 commit comments

Comments
 (0)