Skip to content

Commit 46d0934

Browse files
MichaelChiricoaitapben-schwen
authored
Backport deparse1() (#7823)
* backport deparse1() * Fix %iscall% for complex LHS * Comment, style change * width.cutoff=500L Co-authored-by: Benjamin Schwendinger <52290390+ben-schwen@users.noreply.github.com> * Fix widths according to default argument Co-authored-by: aitap <krylov.r00t@gmail.com> --------- Co-authored-by: Ivan K <krylov.r00t@gmail.com> Co-authored-by: Benjamin Schwendinger <52290390+ben-schwen@users.noreply.github.com>
1 parent 94649d5 commit 46d0934

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

R/data.table.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ replace_dot_alias = function(e) {
567567
stopf("When by and keyby are both provided, keyby must be TRUE or FALSE")
568568
}
569569
if (missing(by)) { missingby=TRUE; by=bysub=NULL } # possible when env is used, PR#4304
570-
else if (verbose && !is.null(env)) catf("Argument '%s' after substitute: %s\n", "by", paste(deparse(bysub, width.cutoff=500L), collapse="\n"))
570+
else if (verbose && !is.null(env)) catf("Argument '%s' after substitute: %s\n", "by", deparse1(bysub, collapse="\n"))
571571
}
572572
bynull = !missingby && is.null(by) #3530
573573
byjoin = !is.null(by) && is.symbol(bysub) && bysub==".EACHI"
@@ -632,7 +632,7 @@ replace_dot_alias = function(e) {
632632
substitute2(.j, env),
633633
list(.j = substitute(j))
634634
))
635-
if (missing(jsub)) {j = substitute(); jsub=NULL} else if (verbose && !is.null(env)) catf("Argument '%s' after substitute: %s\n", "j", paste(deparse(jsub, width.cutoff=500L), collapse="\n"))
635+
if (missing(jsub)) {j = substitute(); jsub=NULL} else if (verbose && !is.null(env)) catf("Argument '%s' after substitute: %s\n", "j", deparse1(jsub, collapse="\n"))
636636
}
637637
}
638638
if (!missing(j)) {
@@ -722,7 +722,7 @@ replace_dot_alias = function(e) {
722722
substitute2(.i, env),
723723
list(.i = substitute(i))
724724
))
725-
if (missing(isub)) {i = substitute(); isub=NULL} else if (verbose && !is.null(env)) catf("Argument '%s' after substitute: %s\n", "i", paste(deparse(isub, width.cutoff=500L), collapse="\n"))
725+
if (missing(isub)) {i = substitute(); isub=NULL} else if (verbose && !is.null(env)) catf("Argument '%s' after substitute: %s\n", "i", deparse1(isub, collapse="\n"))
726726
}
727727
}
728728
if (!missing(i)) {
@@ -2252,7 +2252,7 @@ replace_dot_alias = function(e) {
22522252

22532253
# What's the name of the top-level call in 'j'?
22542254
# NB: earlier, we used 'as.character()' but that fails for closures/builtins (#6026).
2255-
root_name = function(jsub) if (is.call(jsub)) paste(deparse(jsub[[1L]]), collapse = " ") else ""
2255+
root_name = function(jsub) if (is.call(jsub)) deparse1(jsub[[1L]], width.cutoff=60L) else ""
22562256

22572257
DT = function(x, ...) { #4872
22582258
old = getOption("datatable.optimize")

R/transpose.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ tstrsplit = function(x, ..., fill=NA, type.convert=FALSE, keep, names=FALSE) {
5151
if(!n) stopf("The argument 'type.convert' does not support empty list.")
5252
is_named = nzchar(names(type.convert))
5353
all_is_named = length(is_named) && all(is_named) # because all(is_named)=TRUE if is_named=NULL <-- names(type.convert)=NULL
54-
last_item = paste(deparse(substitute(type.convert)[[n + 1L]], width.cutoff=500L), collapse=" ")
54+
last_item = deparse1(substitute(type.convert)[[n + 1L]])
5555
if (!all_is_named) {
5656
if (!(sum(!is_named) == 1L && !is_named[n] && is.function(type.convert[[n]])))
5757
stopf("When the argument 'type.convert' contains an unnamed element, it is expected to be the last element and should be a function. More than one unnamed element is not allowed unless all elements are functions with length equal to %d (the length of the transpose list or 'keep' argument if it is specified).", length(keep))

R/utils.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ nan_is_na = function(x) {
1111
stopf("Argument 'nan' must be NA or NaN")
1212
}
1313

14+
# R 4.4.0
15+
if (!exists("deparse1", "package:base")) deparse1 = function(x, collapse=" ", width.cutoff=500L) paste(deparse(x, width.cutoff=width.cutoff), collapse=collapse) # nolint: paste_linter.
16+
1417
# R 4.4.0
1518
if (!exists("%||%", "package:base")) `%||%` <- function(x, y) if (is.null(x)) y else x # nolint: coalesce_linter.
1619

@@ -202,7 +205,7 @@ is_utc = function(tz) {
202205
if (!is.call(e)) return(FALSE)
203206
if (is.name(e1 <- e[[1L]])) return(e1 %chin% f)
204207
if (e1 %iscall% c('::', ':::')) return(e1[[3L]] %chin% f)
205-
paste(deparse(e1), collapse = " ") %chin% f # complicated cases e.g. a closure/builtin on LHS of call; note that format() is much (e.g. 40x) slower than deparse()
208+
deparse1(e1, width.cutoff=60L) %chin% f # complicated cases e.g. a closure/builtin on LHS of call; note that format() is much (e.g. 40x) slower than deparse()
206209
}
207210

208211
# nocov start #593 always return a data.table

0 commit comments

Comments
 (0)