# siunitx error: “invalid-number” from R

I have a document in .Rnw which I use to produce a .texdocument with kntir. I have a problem with the formula \num{\Sexpr{max(degree)}} which in R console produce 12598 but after the running knitr in the .tex document becomes \num{\ensuremath{1.2598\times 10^{4}}}, which create the following error in LaTex:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! siunitx error: "invalid-number"
!
! Invalid numerical input '\protect $\relax 1.2598\times 10^{4}$'.
!
! See the siunitx documentation for further information.
!
! For immediate help type H <return>.
!...............................................

l.466 ... & \num{\ensuremath{1.2598\times 10^{4}}}

I am bit puzzled since in the document I have bigger numbers which do not create any problem when compiling.

These are my /siunitx options

%Separate digits with comma (e.g. 1,000,000)
\usepackage[group-separator={,}]{siunitx}
\sisetup{
detect-all,
detect-inline-family=math,
detect-inline-weight=math,
detect-display-math=true}
-
Any chance of a MWE? –  moewe Sep 30 '13 at 12:03
\ensuremath is problematic, \times probably too. Can't you configure R/knitr to output \num{1.2598E4} (or just 1.598E4 for a S column)? –  Qrrbrbirlbel Sep 30 '13 at 12:06
Nope, no idea. Maybe it is easier to work on R to make sure the input is what I expect. –  Francesco Sep 30 '13 at 12:11