Displaying 15 results from an estimated 15 matches for "as_numeric".
2004 Jun 30
1
AS_NUMERIC and as.numeric - Could someone explain?
...10000 each. With these vectors I
call
.Call("hyp2f1forrey", a, b, b, z, PACKAGE = "hyp2f1")
to access
SEXP hyp2f1forrey(SEXP a, SEXP b, SEXP c, SEXP x)
{
int i,n;
double *xa, *xb, *xc, *xx, *xresr, *xresi;
SEXP resr, resi;
n = LENGTH(a);
PROTECT(a = AS_NUMERIC(a));
PROTECT(b = AS_NUMERIC(b));
PROTECT(c = AS_NUMERIC(c));
PROTECT(x = AS_NUMERIC(x));
PROTECT(resr = NEW_NUMERIC(n));
PROTECT(resi = NEW_NUMERIC(n));
xa = NUMERIC_POINTER(a);
xb = NUMERIC_POINTER(b);
xc = NUMERIC_POINTER(c);
xx = NUMERIC_POINTER(x);
xresr...
2010 Jun 15
1
Error when callin g C-Code
...nes.h>
#include <Rmath.h>
SEXP CSimPoisson(SEXP lambda, SEXP tgrid, SEXP T2M, SEXP Ni, SEXP NT)
{
double sign, EVar;
double *xlambda, *xtgrid, *xT2M, *xNi, *xNT, *xtau;
SEXP tau;
int ltgrid =0;
int i = 0;
int j = 0;
sign = 0;
EVar = 0;
ltgrid = LENGTH(tgrid);
PROTECT(lambda = AS_NUMERIC(lambda));
PROTECT(tgrid = AS_NUMERIC(tgrid));
PROTECT(T2M = AS_NUMERIC(T2M));
PROTECT(Ni = AS_NUMERIC(Ni));
PROTECT(NT = AS_NUMERIC(NT));
PROTECT(tau = NEW_NUMERIC(1));
xlambda = NUMERIC_POINTER(lambda);
xtgrid = NUMERIC_POINTER(tgrid);
xT2M = NUMERIC_POINTER(T2M);
xNi = NUMERIC_POINTER(Ni...
2012 Dec 06
1
Use .Call interface
Hi
I've written the following program:
#include <R.h>
#include <Rdefines.h>
#include "Projector.h"
SEXP Projector2(SEXP L, SEXP G, SEXP W, SEXP xymod, SEXP modif){
int nprot=0;
PROTECT(L=AS_NUMERIC(L));nprot++;
PROTECT(G=AS_NUMERIC(G));nprot++;
PROTECT(W=AS_NUMERIC(W));nprot++;
PROTECT(xymod=AS_INTEGER(xymod));nprot++;
PROTECT(modif=AS_NUMERIC(modif));nprot++;
double *lptr; lptr=REAL(L);
double *gptr; gptr=REAL(G);
double *wptr; wptr=REAL(W);
int *xyptr; xyptr=INTEGER(xymod);
double...
2012 Sep 16
1
possible TZ bug in parseISO8601 - "Error in if (length(c(year, month, day, hour, min, sec)) == 6 && c(year, : [...]"
...ues - and I have definitely
checked and double-checked), the second line (filtered <-
searchVector[dateFilter]) throws this error .
Error in if (length(c(year, month, day, hour, min, sec)) == 6 && c(year, :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In as_numeric(YYYY) : NAs introduced by coercion
2: In as_numeric(YYYY) : NAs introduced by coercion
Checking with debugger() reveals this
> debugger()
Message: Error in if (length(c(year, month, day, hour, min, sec)) == 6 &&
c(year, :
missing value where TRUE/FALSE needed
Available environ...
2012 Dec 10
1
Changing arguments inside .Call. Wise to encourage "const" on all arguments?
...0.1 "Calling .Call". It protects the arguments a and b (needed
??), then changes them.
#include <R.h>
#include <Rdefines.h>
SEXP convolve2(SEXP a, SEXP b)
{
R_len_t i, j, na, nb, nab;
double *xa, *xb, *xab;
SEXP ab;
PROTECT(a = AS_NUMERIC(a)); /* PJ wonders, doesn't this alter
"a" in calling code*/
PROTECT(b = AS_NUMERIC(b));
na = LENGTH(a); nb = LENGTH(b); nab = na + nb - 1;
PROTECT(ab = NEW_NUMERIC(nab));
xa = NUMERIC_POINTER(a); xb = NUMERIC_POINTER(b);
xab = NUMERIC_POI...
2003 May 20
1
building a Win32 DLL with R objects?
...e?
/* this is a test for the r package to access r objects from a c lib */
#include "R.h"
#include "Rdefines.h"
SEXP test_function( SEXP a, SEXP b )
{
int na;
int nb;
int nab;
double *xa;
double *xb;
double *xab;
SEXP ab;
PROTECT( a = AS_NUMERIC( a ) );
PROTECT( b = AS_NUMERIC( b ) );
warning( "you're now in test_function\n" );
na = LENGTH( a );
nb = LENGTH( b );
nab = na + nb - 1;
PROTECT( nab = AS_NUMERIC( nab ) );
xa = NUMERIC_POINTER( a );
xb = NUMERIC_POINTER( b );
xab = NUMERIC_POINTER( ab...
2012 Jul 16
4
Error in as.xts
Hi
I got the following error using as.xts
Error in xts(x, order.by = order.by, frequency = frequency, ...) :
NROW(x) must match length(order.by)
Here is how the data looks like
> d1 <- read.csv(file.path(dataDir,"AppendixA-FishCountsTable-2009.csv"),
as.is=T)
> d1[1:3,]
dive_id date time species count size site depth level
TRANSECT VIS_M
1 62 10/12/2009
2010 Oct 08
1
R CMD SHLIB changes function name when compiling
...ementation with .Call. When
compiling using R CMD SHLIB characters seem to be added to the function
name.
Here's the complete C code from the file summariseMCMC.c:
#include<R.h>
#include<Rdefines.h>
#include<Rinternals.h>
void summariseMCMC(SEXP data) {
PROTECT(data=AS_NUMERIC(data));
UNPROTECT(1);
}
Then after compiling (R CMD SHLIB summariseMCMC.c) & loading the .dll
dyn.load("C:/R/R-2.11.1/bin/summariseMCMC.dll")
is.loaded("_Z13summariseMCMCP7SEXPREC")
[1] TRUE
is.loaded("summariseMCMC")
[1] FALSE
Just wondering if anyone ha...
2003 May 21
2
moving onto returning a data.frame?
...m_in )
{
int *mdims, n, p, i;
double *mm;
SEXP m_out;
SEXP nms;
if( !isMatrix( m_in ) )
{
error("m_in must be a matrix");
}
mdims = INTEGER( GET_DIM( m_in ) );
n = mdims[0];
p = mdims[1];
PROTECT( m_out = NEW_NUMERIC( p ) );
PROTECT( m_in = AS_NUMERIC( m_in ) );
PROTECT( nms = GET_COLNAMES( GET_DIMNAMES( m_in ) ) );
/* here you'll disect the incoming data.frame into the vectors you'll
pass into your simulation code */
/* get the vectors based on the column names to make sure the sequence
isn't important */
/* crunch,...
2005 Sep 13
3
NUMERIC_POINTER question
Dear R-developers,
Using .Call I pass a S4 class with e.g. the following class definition:
setClass("mmatrix",representation(
data="matrix")
)
On the "C side" i do
mat = GET_SLOT(vs,install("data"));
and then:
printf("%f\n",NUMERIC_POINTER(mat)[1]);
The above print statement produces the correct output if
xx<- new("mmatrix")
2016 May 14
2
R external pointer and GPU memory leak problem
...al pointer ext,?
/*
define function to create a vector in GPU?
by transferring a R's vector to GPU.
input is R's vector and its length,?
output is a R external pointer
pointing to GPU vector(device)
*/
SEXP createGPU(SEXP input, SEXP n)
{ ?
int *lenth = INTEGER(n);
? ? ? ?PROTECT (input = AS_NUMERIC (input));
? ? ? ?double * temp;?
? ? ? ?temp = REAL(input);
double *x; ? ? ? ? ? ? ? ##here is the step which causes the memory leak
cudacall(cudaMalloc((void**)&x, *lenth * sizeof(double)));
//protect the R external pointer from finalizer
SEXP ext = PROTECT(R_MakeExternalPtr(x, R_NilValue, R_N...
2003 Dec 09
1
R Interface handholding
...tems programmer, and am, on the request
of several users of our software, working on generating R interfaces.
For starters, I've written the following R function (which compiles):
SEXP myincr(SEXP Rinput)
{ // Returns input integer incremented by one
int input;
SEXP returner;
PROTECT(Rinput = AS_NUMERIC(Rinput));
input = * INTEGER(Rinput);
input++;
PROTECT(returner = NEW_INTEGER(input));
Rprintf("Hey there\n");
return returner;
}
I've made this into a package, by dropping it into a stub directory
along with something called init.c:
#include "areone.h"
#include <R_ext/...
2012 Jun 08
0
Working with optim in C
...lt; n; i++) { sum += (par[i]*log(lambda[i]) +
(1-par[i]*log(1-lambda[i]))); }
return sum;
}
void optimgr(int n, double *par, double *gr, void *ex)
{
for(int i = 0; i < n; i++) { gr[i] = log(par[i]) - log(1-par[i]); }
}
void Test(SEXP SomeValues)
{
PROTECT(SomeValues = AS_NUMERIC(SomeValues));
double * CValues = NUMERIC_POINTER(SomeValues);
void * optEx, *grEx, *overallEx;
int mask = -1, fncount, grcount, failed;
double *Fmax, *gradients;
int size = sizeof(CValues)/sizeof(double);
vmmin(size, CValues, Fmax,...
2000 May 04
2
alas, no vecnorm
I wanted a function that would give the euclidean distance of a vector.
Then I was happy, because I found vecnorm listed on pg 55 of V&R (3rd
edn) which I had just bought today.
Then I was sad, because R did not have vecnorm.
Then I was happy again, because I bethought myself that I could copy the
function vecnorm from splus to my code.
Then I was sad again because R complained
>
2001 Dec 14
2
colSums in C
Hi, all!
My project today is to write a speedy colSums(), which is a function
available in S-Plus to add the columns of a matrix. Here are 4 ways to do it,
with the time it took (elapsed, best of 3 trials) in both R and S-Plus:
m <- matrix(1, 400, 40000)
x1 <- apply(m, 2, sum) ## R=16.55 S=52.39
x2 <- as.vector(rep(1,nrow(m)) %*% m) ## R= 2.39 S= 8.52
x3 <-