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

Row Emphasis #221

Closed
ghost opened this issue Aug 17, 2015 · 6 comments
Closed

Row Emphasis #221

ghost opened this issue Aug 17, 2015 · 6 comments

Comments

@ghost
Copy link

ghost commented Aug 17, 2015

Background

In markdown, it is possible to create the following table:

Item MWh/y Use Cost
Farm -28309.3 Food 7.2
Wind Turbines 29200.0 Electricity 4.6
Electric Grid -15.5 Power 0.3
Plumbing -5.5 Water 0.2
Pump Station -2.5 Pressure 0.2
Sanitation -1.5 Sewage 0.6
Recycling 0.5 Compost 0.4
Robotics -690.3 Automation 2.0
$plot.device.vehicle.Name$ -122.7 Delivery 0.3
Houses -40.0 Shelter 1.9
Roads Transport 1.2
Total 13.2 18.9

In this table, the MWh/y and Cost columns are bold and fixed width. This allows a custom font to be applied via ConTeXt. The result is quite lovely:

table

Problem

It appears as though pander only supports a single mechanism for column emphasis (the double asterisk for bold).

Request

Is it possible to support both double asterisk and a double asterisk with backticks?

@daroczig
Copy link
Member

That's an interesting proposal, thank you.

We currently have emphasize.rows/cols/cells for italics and emphasize.strong.rows/cols/cells for bold, so might easily add another set of options in pandoc.table and a new helper function like the current emphasize.cells for verbatim support.

But this might suggest to rename the current options a bit, e.g. we might have:

  • emphasize.rows/cols/cells.italics
  • emphasize.rows/cols/cells.bold
  • emphasize.rows/cols/cells.verbtim

And the empasize could fail back to emphasize.italics. @RomanTsegelskyi, what do you think?

@DaveJarvis, until this is done, you might want to add the backticks to the columns before calling pander -- such as:

> i <- head(iris)
> i$Sepal.Width <- sapply(i$Sepal.Width, pandoc.verbatim.return)
> pander(i, emphasize.strong.cols = 2:3)

-------------------------------------------------------------------
 Sepal.Length   Sepal.Width   Petal.Length   Petal.Width   Species 
-------------- ------------- -------------- ------------- ---------
     5.1         **`3.5`**      **1.4**          0.2       setosa  

     4.9          **`3`**       **1.4**          0.2       setosa  

     4.7         **`3.2`**      **1.3**          0.2       setosa  

     4.6         **`3.1`**      **1.5**          0.2       setosa  

     5.0         **`3.6`**      **1.4**          0.2       setosa  

     5.4         **`3.9`**      **1.7**          0.4       setosa  
-------------------------------------------------------------------

Resulting in:

Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5.1 3.5 1.4 0.2 setosa
4.9 3 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
5.0 3.6 1.4 0.2 setosa
5.4 3.9 1.7 0.4 setosa

@romantseg
Copy link
Contributor

This seems like a great idea. @daroczig, wouldn't renaming options be bad for backward compatibility?

@daroczig
Copy link
Member

@RomanTsegelskyi, sure it would :) But it's only the emphasize.rows/cols/cells what would change to emphasize.rows/cols/cells.italics -- and we can keep the old params/functions with the old names acting as the new ones (with a deprecated note in the docs), e.g.:

#' @param emphasize.rows deprecated for \code{emphasize.rows.italics} argument
#' @param emphasize.cols deprecated for \code{emphasize.cols.italics} argument
#' @param emphasize.cells deprecated for \code{emphasize.cells.italics} argument
#' @param emphasize.rows.italics a vector for a two dimensional table specifying which rows to emphasize
#' @param emphasize.cols.italics a vector for a two dimensional table specifying which cols to emphasize
#' @param emphasize.cells.italics a vector for one-dimensional tables or a matrix like structure with two columns for row and column indexes to be emphasized in two dimensional tables. See e.g. \code{which(..., arr.ind = TRUE)}
#' @param emphasize.strong.rows see \code{emphasize.rows} but in bold
#' @param emphasize.strong.cols see \code{emphasize.cols} but in bold
#' @param emphasize.strong.cells see \code{emphasize.cells} but in bold
#' @param emphasize.verbatim.rows see \code{emphasize.rows} but in verbatim
#' @param emphasize.verbatim.cols see \code{emphasize.cols} but in verbatim
#' @param emphasize.verbatim.cells see \code{emphasize.cells} but in verbatim

Well, this would result in even more arguments to pandoc.table, but IMO that's not a big deal.

@romantseg
Copy link
Contributor

Implemented in #222

> pander(head(iris), emphasize.strong.cols = 2:3, emphasize.verbatim.cols = 2)

-------------------------------------------------------------------
 Sepal.Length   Sepal.Width   Petal.Length   Petal.Width   Species 
-------------- ------------- -------------- ------------- ---------
     5.1         **`3.5`**      **1.4**          0.2       setosa  

     4.9          **`3`**       **1.4**          0.2       setosa  

     4.7         **`3.2`**      **1.3**          0.2       setosa  

     4.6         **`3.1`**      **1.5**          0.2       setosa  

      5          **`3.6`**      **1.4**          0.2       setosa  

     5.4         **`3.9`**      **1.7**          0.4       setosa  
-------------------------------------------------------------------

romantseg added a commit that referenced this issue Aug 19, 2015
@daroczig
Copy link
Member

Thanks a lot, @RomanTsegelskyi, closing.
@DaveJarvis, please let us know how this works.

@ghost
Copy link
Author

ghost commented Aug 22, 2015

Brilliant. This will work just fine. Thank you.

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