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

Added support for digits param for each column #190

Merged
merged 3 commits into from
Jul 10, 2015

Conversation

RomanTsegelskyi
Copy link
Contributor

As requested in #146, added support to format using separate digits param for each column.

> t
               drat    wt  qsec vs
Mazda RX4      3.90 2.620 16.46  0
Mazda RX4 Wag  3.90 2.875 17.02  0
Datsun 710     3.85 2.320 18.61  1
Hornet 4 Drive 3.08 3.215 19.44  1
> pandoc.table(t, digits = c(0, 10, 0, 0))

---------------------------------------------
                 drat   wt    qsec   vs 
-------------------- ------ ----- ------ ----
   **Mazda RX4**       4    2.62    16    0  

 **Mazda RX4 Wag**     4    2.875   17    0  

   **Datsun 710**      4    2.32    19    1  

 **Hornet 4 Drive**    3    3.215   19    1  
---------------------------------------------

> pandoc.table(t, digits = c(0, 10, 2, 0))

---------------------------------------------
                 drat   wt    qsec   vs 
-------------------- ------ ----- ------ ----
   **Mazda RX4**       4    2.62  16.46   0  

 **Mazda RX4 Wag**     4    2.875 17.02   0  

   **Datsun 710**      4    2.32  18.61   1  

 **Hornet 4 Drive**    3    3.215 19.44   1  
---------------------------------------------

@daroczig
Copy link
Member

@RomanTsegelskyi are you sure you did not mix up digits and the round parameters?

@RomanTsegelskyi
Copy link
Contributor Author

@daroczig, I am sorry, got confused with original request in #146 where digits param specifies number of decimal digits vs. what is currently supported by pander (number of total digits enforced by format).

> mt
               drat    wt  qsec vs
Mazda RX4      3.90 2.620 16.46  0
Mazda RX4 Wag  3.90 2.875 17.02  0
Datsun 710     3.85 2.320 18.61  1
Hornet 4 Drive 3.08 3.215 19.44  1
> pander(mt, digits = 3)

--------------------------------------------
                 drat   wt   qsec   vs 
-------------------- ------ ---- ------ ----
   **Mazda RX4**      3.9   2.62  16.5   0  

 **Mazda RX4 Wag**    3.9   2.88   17    0  

   **Datsun 710**     3.85  2.32  18.6   1  

 **Hornet 4 Drive**   3.08  3.21  19.4   1  
--------------------------------------------

> xtable(mt, digits = 3)
% latex table generated in R 3.1.3 by xtable 1.7-4 package
% Tue Jun 30 21:57:31 2015
\begin{table}[ht]
\centering
\begin{tabular}{rrrrr}
  \hline
 & drat & wt & qsec & vs \\ 
  \hline
Mazda RX4 & 3.900 & 2.620 & 16.460 & 0.000 \\ 
  Mazda RX4 Wag & 3.900 & 2.875 & 17.020 & 0.000 \\ 
  Datsun 710 & 3.850 & 2.320 & 18.610 & 1.000 \\ 
  Hornet 4 Drive & 3.080 & 3.215 & 19.440 & 1.000 \\ 
   \hline
\end{tabular}
\end{table}

By looking online seems that former is harder to achieve (SO), but IMHO makes a bit more sense than the latter. I was almost successful getting similar same behaviour as we currently have just with vector for digits, like

> pander(mt, digits = c(1,4,2,0))

---------------------------------------------
                 drat   wt    qsec   vs 
-------------------- ------ ----- ------ ----
   **Mazda RX4**       4    2.62    16    0  

 **Mazda RX4 Wag**     4    2.875   17    0  

   **Datsun 710**      4    2.32    19    1  

 **Hornet 4 Drive**    3    3.215   19    1  
---------------------------------------------

However, I started wondering if we should keep the current approach or switch to one like in xtable?

@daroczig
Copy link
Member

daroczig commented Jul 2, 2015

I'd stick with the separate digits and round parameters -- although it might not be trivial for a newcomer, but that's pretty standard in R, and a nice approach anyway.

I'd go with an approach where both digits and round parameters can be provided as a vector. What do you think?

@RomanTsegelskyi
Copy link
Contributor Author

I think that is a reasonable suggestion. I fixed the implementation accordingly. It came out a bit more complicated that I expected, due to need to handle matrixes separately because matrix columns can't be formated separately (as soon as first column is formatted all others are formatted too).

@RomanTsegelskyi
Copy link
Contributor Author

Before only empty 2D objects were converted to data.frame, all other were untouched. Now conversion to data.frame will also happen for anything that inherits matrix, but just for digits/round. I checked an it doesn't seem to cause any additional complications.

@daroczig
Copy link
Member

daroczig commented Jul 6, 2015

Looks good, thanks.

RomanTsegelskyi added a commit that referenced this pull request Jul 10, 2015
Added support for round/digits param for each column
@RomanTsegelskyi RomanTsegelskyi merged commit f9a5504 into Rapporter:master Jul 10, 2015
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

Successfully merging this pull request may close these issues.

None yet

2 participants