Skip to content

Get message "cannot do complex assignments in base namespace" error

7 messages · Thon de Boer, Uwe Ligges, Brian Ripley

#
I am constantly running into the problem where I get
error messages like "cannot do complex assignments in
base namespace".

It might have something to do with the fact that R has
not started up completely, since I am trying to run
some R script using Rterm < Rscript.R.

When I perform the same script in a Interactive R
session, the R script has no problem with the
assignments that it deems complex (like assgining a
new value to a slot in a class object).

Also, when I encapsulate the offending scripts inside
a local({ ... }) block, I also do not get the error,
so my theory is that my script is being run in the
wrong namespace, or R has not completely started up
yet or something.

Does anyone have an idea how I can fix this, without
having to run within the local block?

Thanks,

Thon de Boer
#
Could you 

1) Try with --vanilla.
2) Show us a small example.

In general user code should not be assigning in base (are you
using <<- by any chance?), but there is no difference when redirecting
input in Rterm as to where code is run.  (Your command-line flags may
well affect it, though.)
On Sat, 20 Dec 2003, Thon de Boer wrote:

            
`Like' or precisely, and all the same or not?
That should not work: you should need to set a command-line flag
to determine if you want the session saved or not.

Given that a proper version of this is used for all the testing we do, 
we are pretty confident that it does work correctly in a factory-fresh 
environment.
Sorry, we need to know what `this' is, first.
#
Thanks for the fast reply.

When I use --vanilla for Rterm.exe (Using windows
here) I do not get the problem anymore, so that solved
half my problems. Thanks (I had used --slave --no-save
--no-restore)

But I seem to have the problem of getting the error
message "cannot do complex assignments in base
namespace" when I try to run Rgui.exe.

This is what I am trying to do. I would like to run
the Rgui program that would start up and do some
graphical plots or use the fileBrowser() widget to
load some files.

I have created the following BAT file for windows:



@echo off
set R_PROFILE=%1
set %2=%3
set %4=%5
set %6=%7
set %8=%9
cat.exe > GS_R_in.txt
rw1081\bin\Rgui.exe --no-save --no-restore
cat.exe < GS_R_out.txt
del GS_R_in.txt GS_R_out.txt

that is run by my program (GeneSpring).
The first command line argument is the R script that I
want to run and the four consecutive key-value pairs
are the system environment variable that I set that
will be picked up by the R script.
GeneSpring will also pump some data into the STDOUT
that is picked up by the cat.exe program we wrote and
dumps it in a file that is picked up in return by the
R script.

so the complete command would be something like

myR.bat script.R foo bar aap noot mies zus kees bal <
INPUT.txt > OUTPUT.txt

I had to resort to setting the R script as the
R_PROFILE environment variable to force Rgui to start
the R script I give it.

In the R script there seem to be the complex
assignments like

i at expName <- "Just a character string"

where i is a defined class. This is the assignment R
complains about, but only when I run the script as the
R_PROFILE. If I run the script as source() etc. it
runs fine.

Hope this sheds some light on the problem...

Thanks,

Thon
--- Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
#
On Sun, 21 Dec 2003, Thon de Boer wrote:

            
The following is the critical piece of information you omitted
in your first post.

[...]
That's your problem, and it is bad practice.  ?Startup does explain why 
you needed to use local().

You are misusing the site profile; you could equally have used a user 
profile or .First or ....
#
Thon de Boer wrote:
And that's the point! Don't use Rprofile to execute scripts, because
everything assigned in there will be loaded into base on startup. (See
?Startup)
For running scripts I'd recommend to use Rcmd BATCH (you will need Perl,
though), but it's also possible with rterm.exe.

Uwe Ligges
#
On Sun, 21 Dec 2003, Uwe Ligges wrote:

            
Perl is no longer needed.
#
Good...It is getting clearer now and I indeed read
?Startup so that is why I knew i had to use local()
blocks (or use the .First function, but that does not
seem to work in Rterm) in the first place. The problem
there, is that any of the objects that are created in
the local block are afcourse no longer visible when
the R is started. (I know....I want it all....;-))

The reason for using the R_PROFILE variable was
because there seem to be only one USER profile file
that I can use that has a fixed name '.Rprofile' and
from my application I would like to be able to use one
R startup script that simply got the R script name as
its argument. (I guess I could create this .Rprofile
on the fly each time I want to run my program)

Would there be a way to specify on the command line to
use a different profile file on the command line of
Rgui?

Although I have read that 'code gets installed in base
namespace' I still don't understand what it means. Why
was my assignment of new data to a slot in a class
object deemed to be impossible? Was I overwriting
something without knowing it? I had named the variable
i that contained the class object and was that
variable used in base namespace or something?

What I am trying to do is to have the user of my
system only write one script that he could execute
either with the Rgui or the Rterm program for GUI and
BATCH processing. For most of the things the R_PROFILE
hack seem to work, but indeed is not elegant or even
misusing the functionality) so any help in how to set
this up would be apreciated

Thanks again for the help

Thon
--- Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote: