Options               package:R.utils               R Documentation

_T_h_e _O_p_t_i_o_n_s _c_l_a_s_s

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

     Package:  R.utils 
      *Class Options*

     'Object'
      '~~|'
      '~~+--''Options'

     *Directly known subclasses:*
      Settings

     public static class *Options*
      extends Object

     A class to set and get either options stored in a 'list' tree
     structure.

     Each option has a pathname. The format of a pathname is similar to
     a (Unix) filesystem pathname, e.g. "graphics/cex". See examples
     for more details.

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

     Options(options=list(), ...)

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

 options: A tree 'list' structure of options.

     ...: Not used.

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

     Note, this class and its methods do _not_ operate on the global
     options structure defined in R (options).

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

     The constructor returns an Options object.

_F_i_e_l_d_s _a_n_d _M_e_t_h_o_d_s:

     *Methods:*

         'as.character'  Returns a character string version of this object.
         'as.list'       Gets a list representation of the options.
         'equals'        Checks if this object is equal to another Options object.
         'getLeaves'     Gets all (non-list) options in a flat list.
         'getOption'     Gets an option.
         'hasOption'     Checks if an option exists.
         'names'         Gets the full pathname of all (non-list) options.
         'nbrOfOptions'  Gets the number of options set.
         'setOption'     Sets an option.
         'str'           Prints the structure of the options.

     *Methods inherited from Object*:
      $, $<-, [[, [[<-, as.character, attach, attachLocally, clone,
     detach, equals, extend, finalize, getFields, getInstanciationTime,
     getStaticInstance, hasField, hashCode, ll, load, objectSize,
     print, save

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

     Henrik Bengtsson (<URL: http://www.braju.com/R/>)

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

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

     local <- Options()

     # Query a missing option
     cex <- getOption(local, "graphics/cex")
     cat("graphics/cex =", cex, "\n")  # Returns NULL

     # Query a missing option with default value
     cex <- getOption(local, "graphics/cex", defaultValue=1)
     cat("graphics/cex =", cex, "\n")  # Returns NULL

     # Set option and get previous value
     oldCex <- setOption(local, "graphics/cex", 2)
     cat("previous graphics/cex =", oldCex, "\n")  # Returns NULL

     # Set option again and get previous value
     oldCex <- setOption(local, "graphics/cex", 3)
     cat("previous graphics/cex =", oldCex, "\n")  # Returns 2

     # Query a missing option with default value, which is ignored
     cex <- getOption(local, "graphics/cex", defaultValue=1)
     cat("graphics/cex =", cex, "\n")  # Returns 3

     # Query multiple options with multiple default values
     multi <- getOption(local, c("graphics/cex", "graphics/pch"), c(1,2))
     print(multi);

     # Check existance of multiple options
     has <- hasOption(local, c("graphics/cex", "graphics/pch"))
     print(has);

     # Get a subtree of options
     graphics <- getOption(local, "graphics")
     print(graphics)

     # Get the complete tree of options
     all <- getOption(local)
     print(all)

