0

I have the following command with use of the "cat" function:

cat("\\newcommand{\\NetFlowFull}{",ifelse(Direction=="Buy","raise","invest")," ",NetFlow,"}",sep="")

where "Direction" and "NetFlow" are characters defined in R code. Unfortunately, I'm having trouble finding documentation on "cat" and how it relates to "newcommand" as the syntax for the latter is different from what I'm seeing online.

The above code assigns "invest 100" to NetFlowFull; however, I would like to insert a "$" before the 100. How can I do this? Thank you!

  • 8
    7th question: Please add a MWE (tex.meta.stackexchange.com/questions/228) – Dr. Manuel Kuehner Sep 13 '17 at 13:06
  • 5
    You should probably start you question over. What exactly are you trying to do? cat is an R command and \newcommand is LaTeX. Usually these two does not mix. So what are you attempting – daleif Sep 13 '17 at 13:07
  • 1
    perhaps you are looking for \$ (which you presumably need to enter as \\$ here as $100 would start and not end math mode so raise tex errors. For the rest it appears to be about R syntax so not on topic here. – David Carlisle Sep 13 '17 at 13:22
  • It seems like this is really two questions: 1. How to make \newcommand{\NetFlowFull}{invest 100} have a $ in front of the 100, (for which the answer is \$); and 2. How to translate that into R code. Separating your question into those parts will lead to better and quicker answers, and may also help you find your own answer online. – Teepeemm Sep 13 '17 at 16:56
2

Your question is rather unclear and mostly about R not TeX but if

" "

produces a space then changing it to

" \\$"

will produce \$ which will typeset a $ before the number.

cat("\\newcommand{\\NetFlowFull}{",ifelse(Direction=="Buy","raise","invest")," \\$",NetFlow,"}",sep="")
                                                                            ^^^^^
| improve this answer | |

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