observed power
What has this to do with `observed power'?
On Mon, 29 Jan 2001, Richards, Tom wrote:
Hello:
Here is my current version info:
platform i386-pc-mingw32
arch x86
os Win32
system x86, Win32
status
major 1
minor 2.1
year 2001
month 01
day 15
language R
I am using NT 4.0. Modifying some C code I originally did under R version
1.1.1, I find in the R Extensions manual (p. 34), that I need to change
STRING to STRING_ELT
VECTOR to VECTOR_ELT
etc.
I am using VC++ 6.0, and I simply cannot get that change to work. I am
going to just give a simple example which shows what is happening. This
example uses the getAttrib() and getListElement() functions which appear in
many source files. It works perfectly on 1.1.1, but gives an unread memory
error under 1.2.0. Am I doing something wrong here?
First, a revised getListElement function, as suggested in the manual:
static SEXP getListElement(SEXP list, char *str)
{
SEXP elmt = R_NilValue;
SEXP names = getAttrib(list, R_NamesSymbol);
int i;
for (i = 0; i < length(list); i++)
#if R_VERSION < R_Version(1, 2, 0)
if (strcmp(CHAR(STRING(names)[i]), str) == 0)
{
elmt = VECTOR(list)[i];
break;
}
#else
if (strcmp(CHAR(STRING_ELT(names,i)), str) == 0)
{
elmt = VECTOR_ELT(list,i);
break;
}
#endif
return elmt;
}
Now, a simple calling function, called foo(), for Windows:
__declspec (dllexport) SEXP foo(SEXP input)
{
SEXP L,V,tmp;
input = CDR(input);L = CAR(input);
input = CDR(input);V = CAR(input);
tmp = getListElement(L, "b");
return tmp;
}
I want to feed foo() a list and vector in R, so I made the R function
foo <- function(L,V){res <- .External("foo",L,V);res}
and I called
foo(list(a=4,b=6),c(2,4,9))
This command yields 6, as it should, in version 1.1.1, but crashes version 1.2.1, with a "memory not read". If you're still reading at this point, please note that I placed the two C functions in a source file, and at the top I included: #define VC #include <math.h> #include <R.h> #include "Defn.h" #include <Rdefines.h>
Don't use Defn.h! It is not a shipped file and is not for casual use. Quite possibly the problem. You did not tell us how you linked this to make a DLL. Using the tools that come with 1.2.1 and the recommend compiler, this works for me if the non-existent Defn.h is omitted.
Is there something obvious here that I'm missing? thanks in advance. Tom Richards -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._