[rkward-cvs] SF.net SVN: rkward: [1623] trunk/rkward/doc/en/writing_plugins_introduction .docbook

tfry at users.sourceforge.net tfry at users.sourceforge.net
Sun Mar 18 21:31:48 UTC 2007


Revision: 1623
          http://svn.sourceforge.net/rkward/?rev=1623&view=rev
Author:   tfry
Date:     2007-03-18 14:31:48 -0700 (Sun, 18 Mar 2007)

Log Message:
-----------
Note on eval() in the documentation

Modified Paths:
--------------
    trunk/rkward/doc/en/writing_plugins_introduction.docbook

Modified: trunk/rkward/doc/en/writing_plugins_introduction.docbook
===================================================================
--- trunk/rkward/doc/en/writing_plugins_introduction.docbook	2007-03-18 21:23:42 UTC (rev 1622)
+++ trunk/rkward/doc/en/writing_plugins_introduction.docbook	2007-03-18 21:31:48 UTC (rev 1623)
@@ -519,6 +519,21 @@
 <para>
 If the user explicitely asks for a variable to be saved, you will need to assign to that object with the "<<-" operator.
 </para>
+<para>
+One important pitfall is using eval() to evaluate substitutes. Here, you need to note that eval will by default use the current environment for evaluation, i.e. the local one. This will work well most of the times, but if you define any temporary variables in the local environment, and you are trying to fetch user variables of the same name using eval, you will get errors. For example:
+</para>
+<programlisting>
+# "objects" is the name of both a local temporary variable, and a user selected variable
+objects <- substitute (user.var1, user.var2, objects, user.var4)
+# this will fail: objects[3] is "the object named 'objects'", but this now refers to your
+# temporary variable, instead of the user variable
+third <- eval (objects[3])
+# instead, use this:
+third <- eval (objects[3], envir=globalenv())
+</programlisting>
+<para>
+To solve this, specify the evaluation environment explicitely, as shown above. This will generally be globalenv(), i.e. evaluate as if working in the global environment.
+</para>
 </section>
 
 <section id="policyformatting">


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list