Skip to content

Simple R (in Sweave) Question

2 messages · dogle, Dieter Menne

#
I am writing a report using Sweave with specific R output incorporated into
the text using the Sexpr{} command.  I have run into two specific issues:

1)  If the result inside the Sexpr{} command is an integer less than 10 I
would like to print the ?word? for that number ? e.g., ?seven? for 7.
2)  If a p-value is ?equal to zero? to some arbitrary number of decimal
places -- e.g., formatC(pvalue,format=?f?,digits=4) returns 0.0000 -- I
would like to print ?<0.00005?.

I have attempted searching R-help et al but am not sure what keywords to use
for these questions.  I can picture the format of functions to solve these
issues but would be interested in pointers to previous solutions if they
exist.

Thank you in advance for any help.
R version 2.7.2 (2008-08-25) 
i386-pc-mingw32 

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] tcltk     stats     graphics  grDevices utils     datasets  methods  
base     

other attached packages:
 [1] xtable_1.5-3          RODBC_1.2-3           lattice_0.17-13      
 [4] chron_2.3-24          FSA_0.0-13            reshape_0.8.0        
 [7] Rcapture_1.1          quantreg_4.20         SparseM_0.78         
[10] plotrix_2.4-7         MASS_7.2-44           exactRankTests_0.8-17
[13] NCStats_0.0-12        TeachingDemos_2.3     sciplot_1.0-3        
[16] nortest_1.0           multcomp_1.0-2        mvtnorm_0.9-2        
[19] Hmisc_3.4-3           gplots_2.6.0          gtools_2.5.0         
[22] car_1.2-8             FSAdata_0.0-5         gdata_2.4.2          

loaded via a namespace (and not attached):
[1] cluster_1.11.11 grid_2.7.2      tools_2.7.2
#
dogle <DOgle <at> northland.edu> writes:
I try to avoid putting too complex things into Sexpr{}, because the text gets
unreadable. Normally I do the following (not tested), which should also work for
the "seven" example (put the texts into a vector for that)

(My default <<>> settting is hide)

<<>>=  
p = 0.00001
myp = ifelse(p<0.001,"$p<0.001$",paste("$p=",round(p,1),"$",sep="\n"))
@ 


The probability of error is \Sexpr{myp}

Dieter