Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails for empty data.frame #180

Closed
RomanTsegelskyi opened this issue Jun 9, 2015 · 2 comments
Closed

Fails for empty data.frame #180

RomanTsegelskyi opened this issue Jun 9, 2015 · 2 comments

Comments

@RomanTsegelskyi
Copy link
Contributor

While writing some tests, I realized that pander fails for empty data.frames.

> mt <- mtcars[1:3, 1:4]
> mt
               mpg cyl disp  hp
Mazda RX4     21.0   6  160 110
Mazda RX4 Wag 21.0   6  160 110
Datsun 710    22.8   4  108  93
> mt[mt$mpg < 20, ]
[1] mpg  cyl  disp hp  
<0 rows> (or 0-length row.names)
> pander(mt[mt$mpg < 20, ])
Error in value[[jvseq[[jjj]]]] : subscript out of bounds

This doesn't seem to be super important (similar errors are in broom and ascii packages, thought xtable works correctly), but I will still investigate for a fix in the meantime

@daroczig
Copy link
Member

Nice catch!

I think the xtable behavior (printing the header as a one-row table) is a nice solution, although I am not sure if we should print anything for objects without a real header, like:

> xtable::xtable(matrix(0, nrow = 0, ncol = 5))
% latex table generated in R 3.1.3 by xtable 1.7-4 package
% Tue Jun  9 20:42:55 2015
\begin{table}[ht]
\centering
\begin{tabular}{rrrrrr}
  \hline
 & 1 & 2 & 3 & 4 & 5 \\ 
  \hline
\hline
\end{tabular}
\end{table}

Probably I'd return nothing in such case. What do you think?

@RomanTsegelskyi
Copy link
Contributor Author

It turns out there is actually a check for empty data.frames, just it's done too late, since the failure occurs earlier.

I like the current solution of assigning NA in case of empty object. And I agree that in case there is no header nothing should be printed, just like a warning produced. I have submitted a PR #182, let's move our discussion there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants