srapply              package:ShortRead              R Documentation

_A_p_p_l_y-_l_i_k_e _f_u_n_c_t_i_o_n _f_o_r _d_i_s_t_r_i_b_u_t_i_o_n _a_c_r_o_s_s _M_P_I-_b_a_s_e_d _c_l_u_s_t_e_r_s.

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

     This 'lapply' like function evaluates locally or, if 'Rmpi' is
     loaded and workers spawned, across nodes in a cluster. Errors in
     evaluation of 'FUN' generate warnings; results are trimmed to
     exclude results where the error occurs.

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

     srapply(X, FUN, ..., fapply = .fapply(), reduce = .reduce(), verbose = FALSE)

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

       X: Tasks to be distributed. 'X' should be an object for which
          'lapply' or 'sapply' are defined (more precisely,
          'mpi.parLapply', 'mpi.parSapply'). Performance is best when
          these objects are relatively small, e.g., file names,
          compared to the work to be done on each by 'FUN'.

     FUN: A function to be applied to each element of 'X'. The function
          must have '...' or named argument 'verbose' in its signature.
          It is best if it makes no reference to variables other than
          those in its argument list. or in loaded packages (the
          'ShortRead' package is available on remote nodes).

     ...: Additional arguments, passed to 'FUN'.

  fapply: An optional argument defining an 'lapply'-like function to be
          used in partitioning 'X'. See details, below.

  reduce: Optional function accepting a list (the result of 'fapply'
          and summarizing this. The default reports errors in function
          evaluation as warnings, returning the remaining values as
          elements of a list. See details below for additional hints.

 verbose: Report whether evaluation is local or mpi-based; also
          forwarded to 'FUN', allowing detailed reports from remote
          instances.

_D_e_t_a_i_l_s:

     The default value for 'fapply' is available with
     'ShortRead:::.fapply()'. It tests whether 'Rmpi' is loaded and
     workers spawned. If so, the default ensures that 'ShortRead' is
     'require'd on all workers, and then invokes 'mpi.parLapply' with
     arguments 'X', 'FUN', '...', and 'verbose'. The function 'FUN' is
     wrapped so that errors are returned as objects of class 'SRError'
     with type 'RemoteError'.

     If no workers are available, the code evaluates 'FUN' so that
     errors are reported as with remote evaluation.

     Custom 'reduce' functions might be written as
     'reduce=function(lst) unlist(lst, use.names=TRUE)'.

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

     The returned value depends on the value of 'reduce', but by
     default is a list with elements containing the results of 'FUN'
     applied to each of 'X'. Evaluations resulting in an error have
     been removed, and a warning generated.

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

     Martin Morgan <mtmorgan@fhcrc.org>

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

     ## ... or 'verbose' required in argument, 
     srapply(1:10, function(i, ...) i)
     ## collapse result to vector
     srapply(1:10, function(i, ...) i, reduce=unlist)
     x <- srapply(1:10, function(i, ...) {
         if (runif(1)<.2) stop("oops") else i
     })
     length(x) ## trimmed to exclude errors

