printP               package:cwhprint               R Documentation

_P_r_i_n_t _w_i_t_h_o_u_t _s_q_u_a_r_e _b_r_a_c_k_e_t_s, _e_x_p_r_e_s_s_i_o_n _v_a_l_u_e_s _t_o_g_e_t_h_e_r _w_i_t_h _t_h_e_i_r _c_a_l_l _s_t_r_i_n_g_s

_D_e_s_c_r_i_p_t_i_o_n:

     These functions may be helpful for documenting ongoing work using
     '\sink()'. 
      -  'catn(...)' is shorthand for cat(...); cat("\n") 
      -  'mpf(r,n)'  returns "+ r" or "- r", depending on the sign of
     'r', with 'n' decimal digits. Useful in 'Sweave' files \*.Rnw for
     composing text for linear combinations with coefficients shown in
     \Sexp{}. 
      -  'pn()'    is shorthand for cat("\n") which is awkward for me
     to type. 
      -  'prinV'   prints a vector without \[\], in fix format. 
      -  'prinM'   prints a matrix without \[\], in fix format. 
      -  'prinT'   prints an array, TAB delimited. 
      -  'prinE(xsv, ...)'   prints a string expression and its
     evaluation in the form "xsv = evaluation", in vector form. The
     string may contain "'commenting text'; expression(s)", but only
     the last expression will be evaluated. 
      -  'prinL(xs, ...)'    prints a string expression and its
     evaluation in the form "xs \newline evaluation". 
      -  'prinP(xs)'   prints a string argument and evaluates it i.e.
     the body of the function evaluated should contain print and cat
     statements. 
      -  The variants N... prepend a linefeed. 

_U_s_a_g_e:

       mpf(r,after)
       catn(...)
       pn()
       prinV(x,after=2,before)
       prinM(x,after=2,before)
       prinT(x,rownam=FALSE,colnam=FALSE)
       prinE(xsv,...)
       prinL(xs,...)
       prinP(xs)

_A_r_g_u_m_e_n_t_s:

       x: A numerical vector or matrix.

   after: See 'formatFix', the number of decimals after ".".

  before: See 'formatFix', the number of decimals before "."

  rownam: Should row names be printed.

  colnam: Should column names be printed.

     xsv: A string representing a vector expression.

      xs: A string representing an expression.

     ...: Additional parameters for 'print'.

       r: real value.

_N_o_t_e:

     Uses 'formatFix' in package "cwhstring"

_A_u_t_h_o_r(_s):

     Christian W. Hoffmann, christian.hoffmann@wsl.ch, <URL:
     http://www.wsl.ch/staff/christian.hoffmann>

_E_x_a_m_p_l_e_s:

     mpf(pi,5); mpf(-pi,5)

     xx <- options(digits=7)
     x <- matrix(c(5,3,2,7,8.235,exp(1),pi,0,99),3,3)
     m <- matrix(c("a","b c","d","ff"," x","","7","8","99"),3,3)
     dimnames(x) <- list(c("r1","r2","r3"),c("c1","c2","c3"))

     #### In file  T.Rnw:
     ##  <<echo=TRUE>>=
     a <- -2; b <- -4; c <- 7
     ##  @ 
     ##  
     ##  The coefficients are: $a = \Sexpr{a}$, $b = \Sexpr{b}$, $c = \Sexpr{c}$.
     ##  

     ##  For the linear combination $$z = a + bx +cy$$ we have
     ##   $$z = \Sexpr{sprintf(%.4f,a)} \Sexpr{mpf(b,3)} x \Sexpr{mpf(c,5)} y$$
     #### end T.Rnw
     ###  Sweave: T.Rnw .. T.tex .. T.dvi

     prinV(as.vector(x))
     #  5.00  3.00  2.00  7.00  8.24  2.72  3.14  0.00 99.00 

     prinM(x,,3)
     #  5.00  7.00  3.14 
     #  3.00  8.24  0.00 
     #  2.00  2.72 99.00 

     prinT(x,TRUE,TRUE)
     #       c1      c2      c3 
     # r1    5       7       3.14159265358979 
     # r2    3       8.235   0 
     # r3    2       2.71828182845905        99 

     prinT(c(c1="a",c2="b c",c3="d",c4="ff",c5=" x"),TRUE)
     # c1    c2      c3      c4      c5 
     # a     b c     d       ff       x      # the tabs are not visible here

     prinT(c(c1=5,c2=7,c3=1,c4=3),TRUE)
     # 5     7       1       3      # the tabs are not visible here

     ####prinE("x")
     # x =[1]  5.000000  3.000000  2.000000  7.000000  8.235000  2.718282  3.141593
     # [8]  0.000000 99.000000

     ####prinE("'This is a comment: ';3+5;pi-3",digits=4)
     # 'This is a comment: ';3+5;pi-3 =[1] 0.1416

     prinL("x")
     # x 
     #        c1       c2        c3
     # r1  5 7.000000  3.141593
     # r2  3 8.235000  0.000000
     # r3  2 2.718282 99.000000

     catt <- function(x) {cat("This function will write '",x,"' on one line\n") }
     y <- prinP("catt(32)");
     # catt(32) 
     # This function will write ' 32 ' on one line

     ####prinE("y ")
     # y =[1] "catt(32)"

     prinL("y ")
     # y  
     # [1] "catt(32)"

     prinP("y ")
     # y 
      
     options(digits=xx$digits)

