Skip to content

Commit 62fced0

Browse files
author
maechler
committed
deparse() etc: cannot use "nice names" when some are NA_character_;
more logical: also for named list()s git-svn-id: https://svn.r-project.org/R/trunk@73699 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent a08a602 commit 62fced0

File tree

15 files changed

+309
-172
lines changed

15 files changed

+309
-172
lines changed

doc/NEWS.Rd

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,14 @@
124124
of its previous imperfect workaround R code).
125125
126126
\code{dput()}, \emph{etc} now print the \code{names()} information
127-
only once, using the more readable \code{(tag = value)} syntax.
128-
129-
These functions gain a new (partly experimental) control option
130-
\emph{via} \code{.deparseOpts()}, \code{"niceNames"}, which when
131-
set (e.g.\sspace{}as part of \code{"all"}) also use the \code{(tag
132-
= value)} syntax for atomic vectors.
127+
only once, using the more readable \code{(tag = value)} syntax,
128+
notably for \code{list()}s, i.e., including data frames.
129+
130+
These functions gain a new control option \code{"niceNames"} (see
131+
\code{.deparseOpts()}), which when set (as by default) also uses
132+
the \code{(tag = value)} syntax for atomic vectors. OTOH, without
133+
deparse options \code{"showAttributes"} and \code{"niceNames"},
134+
names are no longer shown also for lists.
133135
134136
\code{m:n} now also deparses nicely when \eqn{m > n}.
135137

src/include/Defn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ void R_SetVarLocValue(R_varloc_t, SEXP);
10751075
#define NICE_NAMES 1024
10761076
/* common combinations of the above */
10771077
#define SIMPLEDEPARSE 0
1078-
#define DEFAULTDEPARSE 65 /* KEEPINTEGER | KEEPNA, used for calls */
1078+
#define DEFAULTDEPARSE 1089 /* KEEPINTEGER | KEEPNA | NICE_NAMES, used for calls */
10791079
#define FORSOURCING 95 /* not DELAYPROMISES, used in edit.c */
10801080

10811081
/* Coercion functions */

src/library/base/R/New-Internal.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ rbind <- function(..., deparse.level = 1)
124124
deparse <-
125125
function(expr, width.cutoff = 60L,
126126
backtick = mode(expr) %in% c("call", "expression", "(", "function"),
127-
control = c("keepInteger", "showAttributes", "keepNA"),
127+
control = c("keepNA", "keepInteger", "niceNames", "showAttributes"),
128128
nlines = -1L)
129129
.Internal(deparse(expr, width.cutoff, backtick,
130130
.deparseOpts(control), nlines))

src/library/base/R/dput.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
# https://www.R-project.org/Licenses/
1818

1919
dput <-
20-
function(x, file = "",
21-
control = c("keepNA", "keepInteger", "showAttributes"))
20+
function(x, file = "", ## keep in sync with deparse() ./New-Internal.R :
21+
control = c("keepNA", "keepInteger", "niceNames", "showAttributes"))
2222
{
2323
if(is.character(file))
2424
if(nzchar(file)) {

src/library/base/man/deparse.Rd

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
}
1212
\usage{
1313
deparse(expr, width.cutoff = 60L,
14-
backtick = mode(expr) \%in\%
15-
c("call", "expression", "(", "function"),
16-
control = c("keepInteger", "showAttributes", "keepNA"),
14+
backtick = mode(expr) \%in\% c("call", "expression", "(", "function"),
15+
control = c("keepNA", "keepInteger", "niceNames", "showAttributes"),
1716
nlines = -1L)
1817
}
1918
\arguments{

src/library/base/man/dput.Rd

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% File src/library/base/man/dput.Rd
22
% Part of the R package, https://www.R-project.org
3-
% Copyright 1995-2014 R Core Team
3+
% Copyright 1995-2017 R Core Team
44
% Distributed under GPL 2 or later
55

66
\name{dput}
@@ -13,7 +13,7 @@
1313
}
1414
\usage{
1515
dput(x, file = "",
16-
control = c("keepNA", "keepInteger", "showAttributes"))
16+
control = c("keepNA", "keepInteger", "niceNames", "showAttributes"))
1717

1818
dget(file, keep.source = FALSE)
1919
}
@@ -60,7 +60,7 @@ dget(file, keep.source = FALSE)
6060
designed to be used for transporting \R data, and will work with \R
6161
objects that \code{dput} does not handle correctly as well as being
6262
much faster.
63-
63+
6464
To avoid the risk of a source attribute out of sync with the actual
6565
function definition, the source attribute of a function will never
6666
be written as an attribute.
@@ -98,6 +98,12 @@ dput(xx, "foo", control = "digits17")
9898
dget("foo") - xx # slight rounding on some platforms
9999
dput(xx, "foo", control = "hexNumeric"); dget("foo") - xx
100100
unlink("foo")
101+
102+
xn <- setNames(xx, paste0("pi^",1:3))
103+
dput(xn) # nicer, now "niceNames" being part of default 'control'
104+
dput(xn, control = "S_compat") # no names
105+
## explicitly asking for output as in R < 3.5.0:
106+
dput(xn, control = c("keepNA", "keepInteger", "showAttributes"))
101107
}
102108
\keyword{file}
103109
\keyword{programming}

src/library/utils/R/str.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ str.default <-
212212
has.class <- S4 || !is.null(cl) # S3 or S4
213213
mod <- ""; char.like <- FALSE
214214
if(give.attr) a <- attributes(object)#-- save for later...
215-
dCtrl <- eval(formals(deparse)$control)
215+
dCtrl <- unique(c(eval(formals(deparse)$control), "niceNames"))
216216
if(drop.deparse.attr) dCtrl <- dCtrl[dCtrl != "showAttributes"]
217217
deParse <- function(.) deparse(., width.cutoff = min(500L, max(20L, width-10L)),
218218
control = dCtrl)

0 commit comments

Comments
 (0)