baptiste auguie | 1 Oct 2010 09:17

strange interaction between rasterImage and Grid graphics

Dear all,

This may be specific to Mac, I haven't had a chance to test another
platform. Consider this,

plot(1,1,t="n")
rasterImage(matrix(1),1,1,1,1)
library(grid)
grid.rect(gp=gpar(fill="grey"))

The grid.rect covers the full device window as expected. However, when
I resize the window ever so slightly (interactive device) the rectGrob
is suddenly clipped to the previous plot window. I cannot understand
this behavior, and it doesn't happen if one removes the rasterImage()
call, so I suspect something iffy is going on with the display list or
something.

The only device I've tried is quartz(), x11() crashed with rasterImage,

 *** caught segfault ***
address 0x28, cause 'memory not mapped'

Traceback:
 1: rasterImage(matrix(1), 1, 1, 1, 1)

sessionInfo()
R version 2.11.1 (2010-05-31)
x86_64-apple-darwin9.8.0

locale:
(Continue reading)

Joris Meys | 1 Oct 2010 18:00
Picon
Gravatar

scoping goes wrong when some functions are used within others.

Dear,

I'm following the r tag on stackoverflow.com, and couldn't but notice
there are quite some questions popping up that deal with scoping in
relation to custom functions. I grinded my teeth on it already, and I
have absolutely no clue what goes wrong. The general pattern is as
follows :

ff <- function(x){
    y <- some_value
    some_function(y)
}

> ff(x)
Error in eval(expr, envir, enclos) : object 'y' not found

I tried to report this as a bug earlier, but got the message I used
the wrong channel. I also don't know how to formalize it into a bug
report on the report site. That's why I bring it to your attention
this way, and want to ask you whether this is by design and we're all
doing something wrong, whether these are problems within certain
packages/situations, ...

I solve these problems now by adding an environment to my global
environment, and delete it after the function finished running. But
this can't be the correct way.

The problem is described here :
http://stackoverflow.com/questions/3840769/scoping-and-functions-in-r-2-11-1-whats-going-wrong

(Continue reading)

Erik Iverson | 1 Oct 2010 19:21
Picon

Re: scoping goes wrong when some functions are used within others.


Joris Meys wrote:
> Dear,
> 
> I'm following the r tag on stackoverflow.com, and couldn't but notice
> there are quite some questions popping up that deal with scoping in
> relation to custom functions. I grinded my teeth on it already, and I
> have absolutely no clue what goes wrong. The general pattern is as
> follows :
> 
> ff <- function(x){
>     y <- some_value
>     some_function(y)
> }
> 
>> ff(x)
> Error in eval(expr, envir, enclos) : object 'y' not found

I get:

Error in ff(x) : object 'some_value' not found

which is entirely consistent, since it has not been bound to a value.

> 
> I tried to report this as a bug earlier, but got the message I used
> the wrong channel. I also don't know how to formalize it into a bug
> report on the report site. That's why I bring it to your attention
> this way, and want to ask you whether this is by design and we're all
> doing something wrong, whether these are problems within certain
(Continue reading)

Duncan Murdoch | 1 Oct 2010 19:49
Picon

Re: scoping goes wrong when some functions are used within others.

  On 01/10/2010 12:00 PM, Joris Meys wrote:
> Dear,
>
> I'm following the r tag on stackoverflow.com, and couldn't but notice
> there are quite some questions popping up that deal with scoping in
> relation to custom functions. I grinded my teeth on it already, and I
> have absolutely no clue what goes wrong. The general pattern is as
> follows :

I think each of the reports is really a separate bug, mostly in the 
implementation of "some_function". As far as I could see, only the last one

|y<- new.env()
with(y, x<- 1)
f<- function(env,z) {
     with(env, x+z)
}
f(y,z=1)
|

involves base R functions, and there I think the problem is with your 
reading of the documentation, not with the function. The documentation 
may suggest that should work by saying "The environment has the caller's 
environment as its parent", but there's no way it possibly could. 
Environments only have one parent. If you read carefully you'll see that 
this is documented correctly in "(Note: if ‘data’ is already an 
environment then this is used with its existing parent.)"

Duncan Murdoch

(Continue reading)

William Dunlap | 1 Oct 2010 19:56
Favicon

Re: scoping goes wrong when some functions are used within others.

One of the complaints in your stackoverlow references
concerned doBy::transformBy and the error message came
from eval().  Using eval() means you are throwing the
usual scoping rules out the window and making up some
new ones.  Using a non-core package means you are at
the mercy of its writer.

In transformBy I believe there is an error in the use
of parent.frame() that can be fixed by changing the
current

  > head(doBy::transformBy)

  1 function (formula, data, ...)                                 
  2 {                                                             
  3     transform2 <- function(data, ...) {                       
  4         e <- eval(substitute(list(...)), data, parent.frame())
  5         tags <- names(e)                                      
  6         inx <- match(tags, names(data))

to

  > head(transformBy)

  1 function (formula, data, ...)                               
  2 {                                                           
  3     PARENT.FRAME <- parent.frame()                          
  4     transform2 <- function(data, ...) {                     
  5         e <- eval(substitute(list(...)), data, PARENT.FRAME)
  6         tags <- names(e)             
(Continue reading)

Jeffrey Horner | 1 Oct 2010 23:49
Picon
Gravatar

Will PrintWarnings remain non static?

Hi,

The C function PrintWarnings is currently not in the C API, but it is
declared non static in the svn trunk as of revision 53110 . As this is
the only function that creates the last.warning object used by the R
function warnings(), I think it would be useful for programs that
embed R to be able to call it.

So, will it remain non static, that is callable although it's not
declared in the public C API?

Thanks,

Jeff

Joris Meys | 1 Oct 2010 23:48
Picon
Gravatar

Re: scoping goes wrong when some functions are used within others.

Thank you for all your answers, this really helped me out. I've been
digging into scoping rules in R and although I'm going to need quite
some more studying to fully grasp it, I do see where the errors come
from.

Thanks again.

 <at> Erik : I know that some_value was not declared. I just gave some
pseudo-code to illustrate the general pattern of the errors, to
indicate why I thought they were linked. Sorry if I wasn't clear
enough on that one.

Cheers
Joris

On Fri, Oct 1, 2010 at 7:21 PM, Erik Iverson <eriki <at> ccbr.umn.edu> wrote:
>
>
> Joris Meys wrote:
>>
>> Dear,
>>
>> I'm following the r tag on stackoverflow.com, and couldn't but notice
>> there are quite some questions popping up that deal with scoping in
>> relation to custom functions. I grinded my teeth on it already, and I
>> have absolutely no clue what goes wrong. The general pattern is as
>> follows :
>>
>> ff <- function(x){
>>    y <- some_value
(Continue reading)

Hervé Pagès | 2 Oct 2010 03:31

cleanup_pkg() in tools:::.build_packages() is broken

Hi,

The cleanup_pkg() function defined the big tools:::.build_packages() 
function in tools/R/build.R is currently broken. When Makefiles are
used cleanup_pkg() doesn't clean anything because of the way system2()
is called.

For example, the call to Ssystem() on line 304 (Ssystem is a silent
version of system2) is basically trying to do this:

   > system2(paste(Sys.getenv("MAKE", "make"), makefiles, "clean"))
   sh: make -f '/home/hpages/R-2.12/etc//Makeconf' -f Makefile clean: 
not found

But it seems that with this new system2(), the arguments to the system
command need to be passed separately thru the 'args' argument.

Cheers,
H.

--

-- 
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M2-B876
P.O. Box 19024
Seattle, WA 98109-1024

(Continue reading)

Deepayan Sarkar | 2 Oct 2010 09:33
Picon

Re: strange interaction between rasterImage and Grid graphics

On Fri, Oct 1, 2010 at 12:17 AM, baptiste auguie
<baptiste.auguie <at> googlemail.com> wrote:
> Dear all,
>
> This may be specific to Mac, I haven't had a chance to test another
> platform. Consider this,
>
> plot(1,1,t="n")
> rasterImage(matrix(1),1,1,1,1)
> library(grid)
> grid.rect(gp=gpar(fill="grey"))
>
> The grid.rect covers the full device window as expected. However, when
> I resize the window ever so slightly (interactive device) the rectGrob
> is suddenly clipped to the previous plot window. I cannot understand
> this behavior, and it doesn't happen if one removes the rasterImage()
> call, so I suspect something iffy is going on with the display list or
> something.

I can reproduce the behaviour on GNU/Linux x11(type="cairo"), but this
is inappropriate mixing of base and grid graphics, so officially I
don't think you are allowed to expect anything at all.

-Deepayan

>
> The only device I've tried is quartz(), x11() crashed with rasterImage,
>
>  *** caught segfault ***
> address 0x28, cause 'memory not mapped'
(Continue reading)

Hadley Wickham | 2 Oct 2010 13:57
Favicon
Gravatar

Eval and the enclos argument

Hi all,

I'm trying to understand the default value of the enclos argument of eval:

  enclos = if(is.list(envir) || is.pairlist(envir)) parent.frame()
else baseenv()

Why isn't it just

  enclos = parent.frame()

given that enclos is only meaningful (given my reading of the
documentation) when envir is not an environment already.

Hadley

--

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/


Gmane