mvbutils-operators         package:mvbutils         R Documentation

_U_t_i_l_i_t_y _o_p_e_r_a_t_o_r_s

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

     Succinct or convenience operators

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

     a %&% b
     a %!in% b
     x %is.not.a% what
     x %is.a% what
     x %is.not.an% what
     x %is.an% what
     vector %except% condition
     x %matching% patt
     x %that.match% patt
     a %that.are.in% b
     x %without.name% what
     a %in.range% b
     a %such.that% b
     a %SUCH.THAT% b
     from %upto% to
     from %downto% to
     x %where% cond

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

 a, b, vector, condition, x, what, patt, from, to, cond: see "Arguments
          By Function" below.

_V_a_l_u_e:

     %&%: string concatenation via 'paste( a, b, sep="")'

   %!in%: logical negation of '%in%'

  %is.a%: (and '%is.not.a%', '%is.an%', '%is.not.an%') result of
          'inherits' to test class membership

 %except%: 'vector' except those elements that match something in
          'condition'

 %matching%, %that.match%: those elements in 'x' which are
          regexp-matched with any of the 'patt's

 %that.are.in%: those elements in 'a' which are in 'b'

 %without.name%: 'x' except those elements whose names match 'what'

 %in.range%: those elements of 'a' that are >=min(b) and <=max(b)

  %upto%: like ':' except that if 'to<from', numeric(0) is returned
          (useful for coding for-loops)

 %downto%: converse of '%upto%'

 %such.that%, %SUCH.THAT%: subset of 'a' for which 'substitute( b,
          list( .=a))' is TRUE. '%such.that%' uses direct subscripting;
          '%SUCH.THAT%' is more general but slower, using a for-loop.

 %where%: those rows of the data.frame 'x' where 'cond' is satisfied
          (see ARGUMENTS.BY.FUNCTION)

_A_r_g_u_m_e_n_t_s _b_y _f_u_n_c_t_i_o_n:

 %&% a, b:character vectors to be 'paste'd with no separator

 %!_i_n%, %_t_h_a_t._a_r_e._i_n% a, b:vectors (character, numeric, complex, or
     logical).

 %_e_x_c_e_p_t% vector, condition:character or numeric vectors

 %_i_n._r_a_n_g_e% a, b:numeric vectors.

 %_i_s._a%, _e_t_c. x:object whose class is to be checked

 %_i_s._a%, _e_t_c. what:class name

 %_m_a_t_c_h_i_n_g%, %_t_h_a_t._m_a_t_c_h% x:character vector

 %_m_a_t_c_h_i_n_g%, %_t_h_a_t._m_a_t_c_h% patt:character vector of regexps

 %_s_u_c_h._t_h_a_t%, %_S_U_C_H._T_H_A_T% a:vector

 %_s_u_c_h._t_h_a_t%, %_S_U_C_H._T_H_A_T% b:expression containing a '.', to subscript
     'a' with

 %_u_p_t_o%, %_d_o_w_n_t_o% from, to:numeric(1)

 %_w_h_e_r_e% x:data.frame

 %_w_h_e_r_e% cond:unquoted expression to be 'eval'ed in context of 'x',
     then in the calling frame of '%where%' (or .GlobalEnv). Should
     evaluate to logical (or maybe numeric or character); NA is treated
     as FALSE. Wrap 'cond' in parentheses to avoid trouble with
     operator precedence.

 %_w_i_t_h_o_u_t._n_a_m_e% x:object with 'names' attribute

 %_w_i_t_h_o_u_t._n_a_m_e% what:character vector of names to drop

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

     Mark Bravington

_S_e_e _A_l_s_o:

     'bquote'

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

      "a" %&% "b" # "ab"
      1:5 %!in% 3:4 # c( TRUE, TRUE, FALSE, FALSE, TRUE)
      1:5 %that.are.in% 3:4 # c( 3, 4)
      trf <- try( 1+"nonsense")
      if( trf %is.not.a% "try-error") cat( "OK\n") else cat( "not OK\n")
      1:5 %except% c(2,4,6) # c(1,3,5)
      c( alpha=1, beta=2) %without.name% "alpha" # c( beta=2)
      1:5 %in.range% c( 2, 4) # c(F,T,T,T,F)
      c( "cat", "hat", "dog", "brick") %matching% c( "at", "ic") # cat hat brick
      1 %upto% 2 # 1:2
      1 %upto% 0 # numeric( 0); using %upto% rather than : in for-loops can simplify coding
      1 %downto% 0 # 1:0
      1 %downto% 2 # numeric( 0)
      ff <- function( which.row) {
      x <- data.frame( a=1:3, b=4:6)
      x %where% (a==which.row)
      }
      ff( 2) # data.frame( a=2, b=5)
      (1:5) %such.that% (.>2) # 3,4,5
      listio <- list( a=1, b=2)
      chars <- cq( a, b)
      chars %SUCH.THAT% (listio[[.]]==2) # this-is-escaped-codenormal-bracket118bracket-normal; %such.that% won't work because [[]] can't handle xtuples

