Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

how do I change each 0.0 to -- without having to reference each as string type or making the whole table string type? The actual table is quite long and it would take too long to do it manually. For the same reason there would be a marked improvement in readability if the table wasn't cluttered up with lots of zeros.

The final table should look something like

Flow            Bibble         Bobble        Gumph
Extant             1              2             3
Intant             --             4             5
My sainted aunt    --             6             7

using for example the MWE below,

\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstabletypeset[columns/Flow/.style={string type,column type={l}},ignore chars={\^^M},col sep=&,row sep=\\]{
    <<results='asis',echo=FALSE>>=
        someStuff=read.table(textConnection("
                  Flow,   Bibble ,   Bobble ,   Gumph
                Extant,    1,           2,      3
                Intant,    0.0 ,        4,      5
       My sainted aunt,    0.0,         6,      7),header=F,sep=",")
    print(xtable(someStuff),include.rownames=F,include.colnames=F,hline.after=NULL,only.contents=T)
    @
}
\end{document}
share|improve this question
    
Here is one pretty obvious solution, but I'm not sure its the right one. Would be open to deleting this query if its self-evident. Any comments appreciated... if I put the replacement string replace in math-mode it does the trick. so ...,string replace*={0.0}{$-$}, gives me the result I need. –  Tahnoon Pasha Nov 22 '12 at 1:45
2  
The use of string replace sounds like the most simple solution. An alternative would be to write some TeX code which is simular to the clear infinite style (by copy-pasting from the source code). But that is clearly much more involved. –  Christian Feuersänger Nov 22 '12 at 19:52

1 Answer 1

up vote 4 down vote accepted

I don't know if this applies to knitr, but other general cases can be handled by first emptying the @cell content for unwanted entries and then post processing the empty cells with the desired result. Another example can be found in Adjusting command behavior based on argument type

\documentclass{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.8,%supress warnings
     table/zero to dash/.style={
        preproc cell content/.code={%
             \pgfkeysgetvalue{/pgfplots/table/@unprocessed cell content}\pgfmathresult%
             \pgfmathparse{(\pgfmathresult==0?int(1):int(0))}
             \ifnum\pgfmathresult>0\pgfkeyssetvalue{/pgfplots/table/@cell content}{}\fi
        },
        empty cells with={--}% If empty place --
    }
}

\begin{document}
\pgfplotstabletypeset[columns={Flow,Bibble,Bobble,Gumph},% declare column names
columns/Flow/.style={string type,column type={l}},
columns/Bibble/.style={
    zero to dash,
},
col sep=comma
]{
Flow,          Bibble,  Bobble, Gumph
Extant,            1 ,       2,      3
Intant,          0.0 ,       4,      5
My sainted aunt, 0.0 ,       6,      7
}
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.