ess-R-data-view.el icon indicating copy to clipboard operation
ess-R-data-view.el copied to clipboard

incorrect parsing of rownames

Open r2evans opened this issue 9 years ago • 1 comments

When running ess-R-dv-ctable on R's ubiquitous dataset mtcars, there are two things wrong:

|  |                   mpg|cyl| disp| hp|drat|   wt| qsec|vs am|gear|carb|
+--+----------------------+---+-----+---+----+-----+-----+-----+----+----+
|Ma|zda RX4           21.0|  6|160.0|110|3.90|2.620|16.46| 0  1|   4|   4|
|Ma|zda RX4 Wag       21.0|  6|160.0|110|3.90|2.875|17.02| 0  1|   4|   4|
|Da|tsun 710          22.8|  4|108.0| 93|3.85|2.320|18.61| 1  1|   4|   1|
...
  1. The rownames are incorrectly assumed to be 2 characters (because there are <100 rows, perhaps?). This is directly affecting the first column. This is repeated if we remove the first column (mtcars <- mtcars[,-1]) and its first column cyl is now affected. If we remove the rownames (rownames(mtcars) <- NULL), the problem goes away.
  2. The two columns vs and am do not have a separator pipe | between them.

r2evans avatar Jan 15 '15 17:01 r2evans

Perhaps instead of doing this manually in elisp, would it be acceptable to use knitr::kable?

R> knitr::kable(mtcars)


|                    |  mpg| cyl|  disp|  hp| drat|    wt|  qsec| vs| am| gear| carb|
|:-------------------|----:|---:|-----:|---:|----:|-----:|-----:|--:|--:|----:|----:|
|Mazda RX4           | 21.0|   6| 160.0| 110| 3.90| 2.620| 16.46|  0|  1|    4|    4|
|Mazda RX4 Wag       | 21.0|   6| 160.0| 110| 3.90| 2.875| 17.02|  0|  1|    4|    4|
|Datsun 710          | 22.8|   4| 108.0|  93| 3.85| 2.320| 18.61|  1|  1|    4|    1|

The extra rows padding the top are likely for knitr's Rmarkdown ties and can easily be filtered out.

Is it wrong to expect the user will have knitr installed? (If they've installed RStudio -- even if they don't use it regularly -- they already have knitr.)

r2evans avatar Jan 15 '15 18:01 r2evans