Bugzilla – Bug 15118
error in plot(table(c('a','a')))
Last modified: 2012-12-25 02:03:02 UTC
there appears to be something strange with the plotting of tables of 1
dimension; if I attempt to make a plot of a table of characters with only
1 value I get an error (Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ). With more than one value I don't get
errors, neither with integers (even if only 1 value):
tbl.char1 <- table(c('a','a'))
tbl.char2 <- table(c('a','a','b'))
tbl.int1 <- table(c(1,1))
# no errors:
R version 2.14.0 (2011-10-31)
Platform: i686-pc-linux-gnu (32-bit)
 LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
 LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
 LC_PAPER=C LC_NAME=C
 LC_ADDRESS=C LC_TELEPHONE=C
 LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
 stats graphics grDevices utils datasets methods base
See also mails on the R-help mailing list with same subject for suggestions.
Here's the last mail in the R-help/R-devel mail list discussion with an overview of the discussion and suggested solution:
R. Michael Weylandt email@example.com
3:22 PM (17 hours ago)
to R, Rui, l.pagie
Should I file an issue for this in the bug tracker?
Slighly rearranged discussion with reproducible example follows on below.
> Em 26-11-2012 21:39, R. Michael Weylandt escreveu:
>> On Mon, Nov 26, 2012 at 2:41 PM, Ludo Pagie <firstname.lastname@example.org> wrote:
>>> tbl.char1 <- table(c('a','a'))
>>> tbl.char2 <- table(c('a','a','b'))
>>> tbl.int1 <- table(c(1,1))
>>> # error:
>>> # no errors:
>> Confirmed in current R-devel. It seems to arise from plot.table's use
>> of seq.int(x) when the dimnames of the table are not integers. I'm not
>> sure if this shouldn't be seq_along(x) instead, but I'm not sure I
>> totally follow the internal logic, so perhaps someone can offer second
On Mon, Nov 26, 2012 at 11:34 PM, Rui Barradas <email@example.com> wrote:
> I'd change "when the dimnames of the table are not integers "
> to not numeric as that's what the code for plot.table tests. And it
> seems to come from seq.int, since with table value
> of 2, seq.int produces a vector of length 2 but the table length is 1:
> seq_along seems to solve the matter.
Thanks, now fixed in R-devel and soon R-patched.