Re: [Rd] Problems connecting to httpd help server with some browsers

2009-09-29 Thread Jeff Horner

Simon Urbanek wrote:
[...]
I don't have konqueror at hand, so I have tested and fixed the lynx case 
(lynx is acting as an HTTP/1.0 client and expects non-persistent 
connection). With some luck the fix may solve the konqueror issue as 
well (although I'd be a bit surprised if konqueror was not 1.1-capable..).


Konqueror didn't like the extra newline in the Location header:

Index: src/library/tools/R/dynamicHelp.R
===
--- src/library/tools/R/dynamicHelp.R   (revision 49890)
+++ src/library/tools/R/dynamicHelp.R   (working copy)
@@ -172,7 +172,7 @@
return(list(payload = paste('Redirect to "',

 basename(file), '"', sep=''),
"content-type" = 'text/html',
-   header = paste('Location: ', file, '\n', sep=''),
+   header = paste('Location: ', file, sep=''),
"status code" = 302L)) # temporary redirect
} else if (length(file) > 1L) {
 paths <- dirname(dirname(file))


Jeff

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] creating environments in package's C code

2009-10-01 Thread Jeff Horner

Martin Becker wrote:

Dear developers,

is it possible to create environments in C code of packages?
Simply using
 SEXP env;
 PROTECT (env  = allocSExp(ENVSXP));
and assigning the enclosing environment with SET_ENCLOS seems to be 
insufficient.


Best wishes,


Here's a function I use in rapache to create one:

static SEXP NewEnv(SEXP enclos){
SEXP env;
PROTECT(env = allocSExp(ENVSXP));

SET_FRAME(env, R_NilValue);
SET_ENCLOS(env, (enclos)? enclos: R_GlobalEnv);
SET_HASHTAB(env, R_NilValue);
SET_ATTRIB(env, R_NilValue);

UNPROTECT(1);

return env;
}


and an example that creates a new environment and then assigns a 
variable named OK an integer vector length 1 with value 0:


SEXP env = NewEnv(R_GlobalEnv);
defineVar(install("OK"),NewInteger(0),env);

Best

Jeff

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] creating environments in package's C code

2009-10-01 Thread Jeff Horner

Jeff Horner wrote:

Martin Becker wrote:

Dear developers,

is it possible to create environments in C code of packages?
Simply using
 SEXP env;
 PROTECT (env  = allocSExp(ENVSXP));
and assigning the enclosing environment with SET_ENCLOS seems to be 
insufficient.


Best wishes,


Here's a function I use in rapache to create one:

static SEXP NewEnv(SEXP enclos){
SEXP env;
PROTECT(env = allocSExp(ENVSXP));

SET_FRAME(env, R_NilValue);
SET_ENCLOS(env, (enclos)? enclos: R_GlobalEnv);
SET_HASHTAB(env, R_NilValue);
SET_ATTRIB(env, R_NilValue);

UNPROTECT(1);

return env;
}


Oops! I forgot the definition of my simple function NewInteger:

static SEXP NewInteger(int i){
SEXP val;
PROTECT(val = NEW_INTEGER(1));
INTEGER_DATA(val)[0] = i;
UNPROTECT(1);
return val;
}




and an example that creates a new environment and then assigns a 
variable named OK an integer vector length 1 with value 0:


SEXP env = NewEnv(R_GlobalEnv);
defineVar(install("OK"),NewInteger(0),env);

Best

Jeff

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] creating environments in package's C code

2009-10-01 Thread Jeff Horner

Simon Urbanek wrote:

Jeff,

On Oct 1, 2009, at 12:37 , Jeff Horner wrote:


Jeff Horner wrote:

Martin Becker wrote:

Dear developers,

is it possible to create environments in C code of packages?
Simply using
SEXP env;
PROTECT (env  = allocSExp(ENVSXP));
and assigning the enclosing environment with SET_ENCLOS seems to be 
insufficient.


Best wishes,

Here's a function I use in rapache to create one:
static SEXP NewEnv(SEXP enclos){
   SEXP env;
   PROTECT(env = allocSExp(ENVSXP));
   SET_FRAME(env, R_NilValue);
   SET_ENCLOS(env, (enclos)? enclos: R_GlobalEnv);
   SET_HASHTAB(env, R_NilValue);
   SET_ATTRIB(env, R_NilValue);
   UNPROTECT(1);
   return env;
}




eek ... that some dangerous bit of code ;). I think Rf_NewEnviroment is 
safer even if it's not the headers :P.


Interesting. I know that I patterned that function after some grepping 
for ENVSXP, probably src/main/serialize.c's ReadItem() as it's similar. 
Plus I only used what was available from the public headers.


So, if Rf_NewEnviroment is the right way to do it then make it public ;P.





Oops! I forgot the definition of my simple function NewInteger:

static SEXP NewInteger(int i){
   SEXP val;
   PROTECT(val = NEW_INTEGER(1));
   INTEGER_DATA(val)[0] = i;
   UNPROTECT(1);
   return val;
}


I suspect you like reinventing the wheel ;). Your NewInteger is part of 
the R API and is called ScalarInteger(). When you need something, 
chances are that R has it already, so it's worth greping through the 
headers (and sometimes even through the main sources).


Yes, that I created NewInteger is a grave oversight on my part. It's 
been around since R's first release (if my svn log research was 
correct). Thanks. I'm putting it on rapache's TODO list to take it out.


Jeff



Cheers,
Simon





and an example that creates a new environment and then assigns a 
variable named OK an integer vector length 1 with value 0:

SEXP env = NewEnv(R_GlobalEnv);
defineVar(install("OK"),NewInteger(0),env);
Best
Jeff
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel






__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Active bindings in attached environments

2009-11-05 Thread Jeff Horner

Hi,

I was wondering if this is expected behavior for active bindings in 
attached environments, or if this is a bug:


> e <- new.env()
> makeActiveBinding('x',function() 'foo',e)
> ls(e)
[1] "x"
> attach(e)
> search()
[1] ".GlobalEnv""e" "package:graphics"
[4] "package:grDevices" "package:datasets"  "package:utils"
[7] "package:methods"   "Autoloads" "package:base"
> x
function() 'foo' # Should this print 'foo' ?

This works as I would expect:

> with(e,x)
[1] "foo"

but this doesn't:

> f <- function() x
> f()
function() 'foo'

However, changing the environment of f does:

> environment(f) <- e
> f()
[1] "foo"


Jeff

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel