Skip to content

Commit

Permalink
formatting of named raw vectors now uses label widths
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@73698 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
maechler committed Nov 9, 2017
1 parent f8207c6 commit a08a602
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
3 changes: 3 additions & 0 deletions doc/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@
\item The self starting function \code{attr(SSlogis, "initial")}
now also works when the y values have exact minimum zero and is
slightly changed in general, behaving symmetrically in the y range.

\item The printing of named raw vectors is now formatted nicely as
for other such atomic vectors, thanks to Lukas Stadler.
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/printvector.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* R : A Computer Language for Statistical Data Analysis
* Copyright (C) 1995-1997, 1998 Robert Gentleman and Ross Ihaka
* Copyright (C) 1998-2014 The R Core Team.
* Copyright (C) 1998-2017 The R Core Team.
* Copyright (C) 1995-1998 Robert Gentleman and Ross Ihaka
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -272,7 +272,7 @@ static void printNamedIntegerVector(int * x, int n, SEXP * names)

static void printNamedRealVector(double * x, int n, SEXP * names)
PRINT_N_VECTOR(INI_F_REAL,
Rprintf("%s%*s",
Rprintf("%s%*s",
EncodeReal0(x[k],w,d,e, OutDec),R_print.gap,""))

#undef INI_F_CPLX
Expand Down Expand Up @@ -312,7 +312,8 @@ static void printNamedStringVector(SEXP * x, int n, int quote, SEXP * names)

static void printNamedRawVector(Rbyte * x, int n, SEXP * names)
PRINT_N_VECTOR(formatRaw(x, n, &w),
Rprintf("%s%*s", EncodeRaw(x[k], ""), R_print.gap,""))
Rprintf("%*s%s%*s", w - 2, "",
EncodeRaw(x[k], ""), R_print.gap,""))

attribute_hidden
void printNamedVector(SEXP x, SEXP names, int quote, const char *title)
Expand Down
4 changes: 2 additions & 2 deletions tests/Examples/stats-Ex.Rout.save
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

R Under development (unstable) (2017-10-29 r73639) -- "Unsuffered Consequences"
R Under development (unstable) (2017-11-09 r73697) -- "Unsuffered Consequences"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

Expand Down Expand Up @@ -4322,7 +4322,7 @@ X-squared = 4.3, df = 4, p-value = 0.3669
>
> ### Name: coef
> ### Title: Extract Model Coefficients
> ### Aliases: coef coefficients
> ### Aliases: coef coefficients coef.default coef.aov
> ### Keywords: regression models
>
> ### ** Examples
Expand Down
16 changes: 12 additions & 4 deletions tests/reg-tests-2.R
Original file line number Diff line number Diff line change
Expand Up @@ -3047,18 +3047,26 @@ summary(1L)
str(I(m <- matrix(pi*1:4, 2)))
## did look ugly (because of toString() for numbers) in R <= 3.3.1

## check automatic coercions from double to integer

# these should work due to coercion
## check automatic coercions from double to integer
##
## these should work due to coercion
sprintf("%d", 1)
sprintf("%d", NA_real_)
sprintf("%d", c(1,2))
sprintf("%d", c(1,NA))
sprintf("%d", c(NA,1))

# these should fail
##
## these should fail
sprintf("%d", 1.1)
sprintf("%d", c(1.1,1))
sprintf("%d", c(1,1.1))
sprintf("%d", NaN)
sprintf("%d", c(1,NaN))


## formatting of named raws:
setNames(as.raw(1:3), c("a", "bbbb", "c"))
## was quite ugly for R <= 3.4.2


20 changes: 15 additions & 5 deletions tests/reg-tests-2.Rout.save
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

R Under development (unstable) (2017-10-29 r73639) -- "Unsuffered Consequences"
R Under development (unstable) (2017-11-09 r73697) -- "Unsuffered Consequences"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

Expand Down Expand Up @@ -7857,9 +7857,10 @@ logical 1
AsIs [1:2, 1:2] 3.14 6.28 9.42 12.57
> ## did look ugly (because of toString() for numbers) in R <= 3.3.1
>
> ## check automatic coercions from double to integer
>
> # these should work due to coercion
> ## check automatic coercions from double to integer
> ##
> ## these should work due to coercion
> sprintf("%d", 1)
[1] "1"
> sprintf("%d", NA_real_)
Expand All @@ -7870,8 +7871,8 @@ logical 1
[1] "1" "NA"
> sprintf("%d", c(NA,1))
[1] "NA" "1"
>
> # these should fail
> ##
> ## these should fail
> sprintf("%d", 1.1)
Error in sprintf("%d", 1.1) :
invalid format '%d'; use format %f, %e, %g or %a for numeric objects
Expand All @@ -7888,3 +7889,12 @@ Error in sprintf("%d", NaN) :
Error in sprintf("%d", c(1, NaN)) :
invalid format '%d'; use format %f, %e, %g or %a for numeric objects
>
>
> ## formatting of named raws:
> setNames(as.raw(1:3), c("a", "bbbb", "c"))
a bbbb c
01 02 03
> ## was quite ugly for R <= 3.4.2
>
>
>

0 comments on commit a08a602

Please sign in to comment.