Permalink
Browse files

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
  • Loading branch information...
maechler
maechler committed Nov 10, 2017
1 parent a08a602 commit 62fced00949b9a261034d24789175b205f7fa866
@@ -124,12 +124,14 @@
of its previous imperfect workaround R code).
\code{dput()}, \emph{etc} now print the \code{names()} information
only once, using the more readable \code{(tag = value)} syntax.
These functions gain a new (partly experimental) control option
\emph{via} \code{.deparseOpts()}, \code{"niceNames"}, which when
set (e.g.\sspace{}as part of \code{"all"}) also use the \code{(tag
= value)} syntax for atomic vectors.
only once, using the more readable \code{(tag = value)} syntax,
notably for \code{list()}s, i.e., including data frames.
These functions gain a new control option \code{"niceNames"} (see
\code{.deparseOpts()}), which when set (as by default) also uses
the \code{(tag = value)} syntax for atomic vectors. OTOH, without
deparse options \code{"showAttributes"} and \code{"niceNames"},
names are no longer shown also for lists.
\code{m:n} now also deparses nicely when \eqn{m > n}.
@@ -1075,7 +1075,7 @@ void R_SetVarLocValue(R_varloc_t, SEXP);
#define NICE_NAMES 1024
/* common combinations of the above */
#define SIMPLEDEPARSE 0
#define DEFAULTDEPARSE 65 /* KEEPINTEGER | KEEPNA, used for calls */
#define DEFAULTDEPARSE 1089 /* KEEPINTEGER | KEEPNA | NICE_NAMES, used for calls */
#define FORSOURCING 95 /* not DELAYPROMISES, used in edit.c */
/* Coercion functions */
@@ -124,7 +124,7 @@ rbind <- function(..., deparse.level = 1)
deparse <-
function(expr, width.cutoff = 60L,
backtick = mode(expr) %in% c("call", "expression", "(", "function"),
control = c("keepInteger", "showAttributes", "keepNA"),
control = c("keepNA", "keepInteger", "niceNames", "showAttributes"),
nlines = -1L)
.Internal(deparse(expr, width.cutoff, backtick,
.deparseOpts(control), nlines))
@@ -17,8 +17,8 @@
# https://www.R-project.org/Licenses/
dput <-
function(x, file = "",
control = c("keepNA", "keepInteger", "showAttributes"))
function(x, file = "", ## keep in sync with deparse() ./New-Internal.R :
control = c("keepNA", "keepInteger", "niceNames", "showAttributes"))
{
if(is.character(file))
if(nzchar(file)) {
@@ -11,9 +11,8 @@
}
\usage{
deparse(expr, width.cutoff = 60L,
backtick = mode(expr) \%in\%
c("call", "expression", "(", "function"),
control = c("keepInteger", "showAttributes", "keepNA"),
backtick = mode(expr) \%in\% c("call", "expression", "(", "function"),
control = c("keepNA", "keepInteger", "niceNames", "showAttributes"),
nlines = -1L)
}
\arguments{
@@ -1,6 +1,6 @@
% File src/library/base/man/dput.Rd
% Part of the R package, https://www.R-project.org
% Copyright 1995-2014 R Core Team
% Copyright 1995-2017 R Core Team
% Distributed under GPL 2 or later
\name{dput}
@@ -13,7 +13,7 @@
}
\usage{
dput(x, file = "",
control = c("keepNA", "keepInteger", "showAttributes"))
control = c("keepNA", "keepInteger", "niceNames", "showAttributes"))
dget(file, keep.source = FALSE)
}
@@ -60,7 +60,7 @@ dget(file, keep.source = FALSE)
designed to be used for transporting \R data, and will work with \R
objects that \code{dput} does not handle correctly as well as being
much faster.
To avoid the risk of a source attribute out of sync with the actual
function definition, the source attribute of a function will never
be written as an attribute.
@@ -98,6 +98,12 @@ dput(xx, "foo", control = "digits17")
dget("foo") - xx # slight rounding on some platforms
dput(xx, "foo", control = "hexNumeric"); dget("foo") - xx
unlink("foo")
xn <- setNames(xx, paste0("pi^",1:3))
dput(xn) # nicer, now "niceNames" being part of default 'control'
dput(xn, control = "S_compat") # no names
## explicitly asking for output as in R < 3.5.0:
dput(xn, control = c("keepNA", "keepInteger", "showAttributes"))
}
\keyword{file}
\keyword{programming}
@@ -212,7 +212,7 @@ str.default <-
has.class <- S4 || !is.null(cl) # S3 or S4
mod <- ""; char.like <- FALSE
if(give.attr) a <- attributes(object)#-- save for later...
dCtrl <- eval(formals(deparse)$control)
dCtrl <- unique(c(eval(formals(deparse)$control), "niceNames"))
if(drop.deparse.attr) dCtrl <- dCtrl[dCtrl != "showAttributes"]
deParse <- function(.) deparse(., width.cutoff = min(500L, max(20L, width-10L)),
control = dCtrl)
Oops, something went wrong.

0 comments on commit 62fced0

Please sign in to comment.