tclVarFun               package:tcltk2               R Documentation

_M_a_n_i_p_u_l_a_t_e _R _v_a_r_i_a_b_l_e_s _a_n_d _f_u_n_c_t_i_o_n_s _f_r_o_m _t_c_l _a_n_d _b_a_c_k

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

     These functions are intended to provide a better "duality" between
     the name of variables in both R and tcl, including for function
     calls. It is possible to define a variable with the same name in R
     and tcl (the content is identical, but copied and coerced in the
     two respective environments). It is also possible to get the value
     of a tcl variable from R, and to call a R function from within
     tcl. These functionnalities are provided in the tcltk package, but
     Tcl variable usually have different internal names as R
     equivalents.

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

       makeTclNames(names, unique = FALSE)
       tclFun(f, name = deparse(substitute(f)))
       tclGetValue(name)
       tclSetValue(name, value)
       tclVarExists(name)
       tclVarFind(pattern)
       tclVarname(name, init = "", keep.existing = TRUE)

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

   names: Transform names so that they are valid for variables in tcl 

  unique: Should these names be unique in the vector? 

       f: An R function. currently, do no support functions with
          arguments. 

    name: The name of a variable 

   value: The value to place in a variable 

 pattern: A pattern to search for 

    init: Initial value to use when creating the variable 

keep.existing: If the tcl variable already exist, should we keep its
          content?  

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

     These functions are similar to 'tclVar()' from package tcltk,
     except for the following change: here, it is possible to propose a
     name for the created tcl variable, or to set or retrieve the
     content of a tcl variable that is not mirrored in R.

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

     Most of these functions return a 'tclVar' object.

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

     Philippe Grosjean

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

     'tk2theme'

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

       ## Not run: 
         ## These cannot be run by examples() but should be OK when pasted
         ## into an interactive R session with the tcltk package loaded

             ## Tcl functions and variables manipulation
         tclVarExists("tcl_version")
         tclVarExists("probably_non_existant")
         tclVarFind("tcl*")

         # Using tclVarname() and tclGetValue()... intented for better match between R and Tcl variables
         Test <- tclVarname("Test", "this is a test!")
         # Now 'Test' exist both in R and in Tcl... In R, you need to use tclvalue(Test) to retrieve its content
         # If a variable already exists in Tcl, its content is preserved using keep.existing = TRUE
         .Tcl("set A_Variable {just to test...}") # Create a variable in Tcl and assign "just a test..." to it
         A_Variable <- tclVarname("A_Variable", "something else?") # Create the dual variable with same name
         tclvalue(A_Variable) # Content of the variable is not changed!

         # If you want to retrieve the content of a Tcl variable, but do not want to create a reference to it in R, use:
         .Tcl("set Another_Variable {something in it}")  # Create a Tcl variable, not visible from R
         tclGetValue("Another_Variable") # Get its content in R
       ## End(Not run)

