search for: coercevector

Displaying 20 results from an estimated 55 matches for "coercevector".

2004 Nov 29
1
data is getting corrupted
...plot_slp_sexp = get_list_element( plot_list, "slope" ); plot_asp_sexp = get_list_element( plot_list, "aspect" ); plot_h20_sexp = get_list_element( plot_list, "whc" ); plot_map_sexp = get_list_element( plot_list, "map" ); PROTECT( plot_plot_sexp = coerceVector( plot_plot_sexp, INTSXP ) ); PROTECT( plot_lat_sexp = coerceVector( plot_lat_sexp, REALSXP ) ); PROTECT( plot_long_sexp = coerceVector( plot_long_sexp, REALSXP ) ); PROTECT( plot_elev_sexp = coerceVector( plot_elev_sexp, REALSXP ) ); PROTECT( plot_slp_sexp = coerceVector( plot_slp_sexp,...
2012 Dec 15
3
interfacing with .Call
...following: #include <R.h> #include <Rinternals.h> //* the Projector part *// void Projector(double *L, int *dimL, double *G, int *dimG, double *W, int *dimW, int *xymod, int *dimxy, double *modif, int *dimif, double *Lsum) { ...} //* the interface part *// #define getDim(A) INTEGER(coerceVector(getAttrib(A,R_DimSymbol), INTSXP)) SEXP Projector5(SEXP L, SEXP G, SEXP W, SEXP xymod, SEXP modif) { //* digest SEXPs from R *// int *dimL, *dimG, *dimW, *dimxy, *dimif; double *lptr, *gptr, *wptr, *ifptr; int *xyptr; dimL=getDim(L); PROTECT(L=coerceVector(L, REALSXP));...
2013 Apr 17
1
stack imbalance in max.col for non-real matrices
...======================================================= --- array.c (revision 61606) +++ array.c (working copy) @@ -1614,7 +1614,10 @@ SEXP m = CAR(args); int method = asInteger(CADR(args)); int nr = nrows(m), nc = ncols(m), nprot = 1; - if (TYPEOF(m) != REALSXP) PROTECT(m = coerceVector(m, REALSXP)); + if (TYPEOF(m) != REALSXP) { + PROTECT(m = coerceVector(m, REALSXP)); + nprot++; + } SEXP ans = allocVector(INTSXP, nr); PROTECT(ans); R_max_col(REAL(m), &nr, &nc, INTEGER(ans), &method); Thanks, Michael [[alternative HTML version deleted...
2007 Jun 04
2
missing IntegerFromString()
I have created a DLL not so long ago using C code. My code used the IntegerFromString() function that used to be exported in the Rinternals.h header file (and thus easily accessible). Recently I upgraded to R 2.5.0 and my DLL stopped working. I see that the IntegerFromString() function is not exported in any of the header files in the RHOME\include directory. Is it possible for me to use it
2004 Nov 12
1
dyn.load problem
...e: Par??metro incorreto. (Incorrect Parameter) My C code is (extracted form Writing R Extension): #include <R.h> #include <Rinternals.h> SEXP convolve2(SEXP a, SEXP b) { R_len_t i, j, na, nb, nab; double *xa, *xb, *xab; SEXP ab; PROTECT(a = coerceVector(a, REALSXP)); PROTECT(b = coerceVector(b, REALSXP)); na = length(a); nb = length(b); nab = na + nb - 1; PROTECT(ab = allocVector(REALSXP, nab)); xa = REAL(a); xb = REAL(b); xab = REAL(ab); for(i = 0; i < nab; i++) xab[i] = 0.0; for(i = 0; i < n...
2008 Apr 10
1
Computing time when calling C functions - why does an extra function call induce such an overhead?
...oducing the extra function call to mysolve2? I am on windows XP using R 2.6.1 Best regards S?ren SEXP mysolve1(SEXP Ain, SEXP Bin, SEXP tolin) { int *Adims, *Bdims; double tol = asReal(tolin); SEXP A, B; PROTECT(A = duplicate(Ain)); PROTECT(B = duplicate(Bin)); Adims = INTEGER(coerceVector(getAttrib(A, R_DimSymbol), INTSXP)); Bdims = INTEGER(coerceVector(getAttrib(B, R_DimSymbol), INTSXP)); int nrA, ncB; double *Ap, *Bp; nrA = Adims[0]; ncB = Bdims[1]; Ap = REAL(A); Bp = REAL(B); /* int info, *ipiv = (int *) R_alloc(nrA, sizeof(int)); */ /* F77_CA...
2004 Nov 07
2
Problem with dyn.load()
...like run the coded write below named conv.c (Example from "Write R Extension") : #include <R.h> #include <Rinternals.h> SEXP convolve2(SEXP a, SEXP b) { R_len_t i, j, na, nb, nab; double *xa, *xb, *xab; SEXP ab; PROTECT(a = coerceVector(a, REALSXP)); PROTECT(b = coerceVector(b, REALSXP)); na = length(a); nb = length(b); nab = na + nb - 1; PROTECT(ab = allocVector(REALSXP, nab)); xa = REAL(a); xb = REAL(b); xab = REAL(ab); for(i = 0; i < nab; i++) xab[i] = 0.0; for(i = 0; i < n...
2005 Aug 20
1
Implementing a single-precision class with raw
...'t seem to be any macros for handling raw vectors in Rdefines.h. I've made a guess at what those macros would be and was wondering whether my guesses were correct and/or might be included in 2.2.0: #define NEW_RAW(n) allocVector(RAWSXP,n) #define RAW_POINTER(x) (RAW(x)) #define AS_RAW(x) coerceVector(x,RAWSXP) I'm not sure whether coerceVector(x,RAWSXP) will actually work. Also, there isn't an Rf_isRaw() function, which would be useful for an IS_RAW(x) macro. Another issue with the "float" class is that it will run into endian issues if it ever gets saved to disk and move...
2014 Oct 22
2
Using a custom memory allocation function in R
...I call something like n <- length(Y) res <- numeric(length=1) .Call("R_allocate_using_myalloc", n, res) res <- Y - mean(Y) and in C #include <R.h> #include <Rinternals.h> #include <numa.h> SEXP R_allocate_using_myalloc(SEXP R_n, SEXP R_res){ PROTECT(R_n = coerceVector(R_n, INTSXP)); PROTECT(R_res = coerceVector(R_res, REALSXP)); int *restrict n = INTEGER(R_n); R_allocator_t myAllocator; myAllocator.mem_alloc = numa_alloc_onnode; myAllocator.mem_free = numa_free; myAllocator.res = NULL; myAllocator.data = ???; R_res = allocVector3(REALSXP, n, my...
2011 Oct 24
2
C function is wrong under Windows 7
...1.0 / (fchrLen-signLen); for (i = 0; i < fchrLen; ++i) { *(pmiss + i) = tmp; } for (i = 0; i < signLen; ++i) { *(pmiss + sign[i]-1) = 0; } } SEXP getEs(SEXP fchr, SEXP sign) { int i, nfchr, nsign; double *rfchr = REAL(fchr), *res; int *rsign = INTEGER(sign); PROTECT(fchr = coerceVector(fchr, REALSXP)); PROTECT(sign = coerceVector(sign, REALSXP)); nfchr = length(fchr); nsign = length(sign); SEXP es; PROTECT(es = allocVector(REALSXP, nfchr)); res = REAL(es); double nr = getNr(rfchr, rsign, nsign); SEXP phit; PROTECT(phit = allocVector(REALSXP, nfchr)); double *rphit;...
2020 Aug 23
2
sum() vs cumsum() implicit type coercion
...py$long) : invalid 'type' (character) of argument > cumsum(tryjpy$long) [1] 0.0022 0.0020 -0.0129 -0.0152 -0.0494 -0.0739 -0.0761 -0.0758 -0.0759 [10] -0.0763 -0.0799 -0.0809 -0.0820 -0.0832 -0.0838 -0.0822 -0.0816 Which I guess is due to the following line in do_cum(): PROTECT(t = coerceVector(CAR(args), REALSXP)); This might be fine and there may be very good reasons why there is no coercion in sum - just seems a little inconsistent in usage Cheers -- Rory
2023 Nov 07
1
c(NA, 0+1i) not the same as c(as.complex(NA), 0+1i)?
...outcome of as.complex(NA) should be, but rather, how I should read code like c(x, y) generally. Till now, I have thought of it like 'c(x, y)' is c(as(x, typeof(y)), y)` when "type(y) > type(x)". Basically in my mind, "coercion" in R <-> as.<newtype>(.) (or coerceVector() in C). So I tracked down the source (which admittedly has been this way for much longer than the present discussion) to see what exactly c() is doing in this case: https://github.com/r-devel/r-svn/blob/71e7480b07767f3b7d5c45a4247959aa4d83d910/src/main/bind.c#L418-L425 And indeed! It's not...
2007 Aug 23
1
.Call and to reclaim the memory by allocVector
...ines.h" SEXP crossprod2(SEXP a, SEXP b); //modified from convolve2 in the R extension //R CMD SHLIB crossprod2.c #include <R.h> #include <Rinternals.h> SEXP crossprod2(SEXP a, SEXP b) { R_len_t i, j, na, nb, nab; double *xa, *xb, *xab; SEXP ab; PROTECT(a = coerceVector(a, REALSXP)); PROTECT(b = coerceVector(b, REALSXP)); na = length(a); nb = length(b); //nab = na + nb - 1; nab=na*nb;// we are doing the cross product PROTECT(ab = allocVector(REALSXP, nab)); xa = REAL(a); xb = REAL(b); xab = REAL(ab); for(i = 0; i &l...
2007 Aug 23
1
.Call and to reclaim the memory by allocVector
...ines.h" SEXP crossprod2(SEXP a, SEXP b); //modified from convolve2 in the R extension //R CMD SHLIB crossprod2.c #include <R.h> #include <Rinternals.h> SEXP crossprod2(SEXP a, SEXP b) { R_len_t i, j, na, nb, nab; double *xa, *xb, *xab; SEXP ab; PROTECT(a = coerceVector(a, REALSXP)); PROTECT(b = coerceVector(b, REALSXP)); na = length(a); nb = length(b); //nab = na + nb - 1; nab=na*nb;// we are doing the cross product PROTECT(ab = allocVector(REALSXP, nab)); xa = REAL(a); xb = REAL(b); xab = REAL(ab); for(i = 0; i &l...
2023 Nov 06
1
c(NA, 0+1i) not the same as c(as.complex(NA), 0+1i)?
...quot;. > A test in data.table was broken by the changes for NA > coercion to complex; the breakage essentially comes from > c(NA, 0+1i) > # vs > c(as.complex(NA), 0+1i) > The former is the output we tested against; the latter is essentially (via > coerceVector() in C) what's generated by our data.table::shift() > However, these are now (r85472) different: > Im(c(NA, 0+1i)) > # [1] NA 1 > Im(c(as.complex(NA), 0+1i)) > # [1] 0 1 > The former matches the behavior of directly using NA_complex_: > Im(...
2023 Nov 05
2
c(NA, 0+1i) not the same as c(as.complex(NA), 0+1i)?
...ad from September "Recent changes to as.complex(NA_real_)". A test in data.table was broken by the changes for NA coercion to complex; the breakage essentially comes from c(NA, 0+1i) # vs c(as.complex(NA), 0+1i) The former is the output we tested against; the latter is essentially (via coerceVector() in C) what's generated by our data.table::shift() However, these are now (r85472) different: Im(c(NA, 0+1i)) # [1] NA 1 Im(c(as.complex(NA), 0+1i)) # [1] 0 1 The former matches the behavior of directly using NA_complex_: Im(c(NA_complex_, 0+1i)) # [1] NA 1 On R4.3.2, they both match th...
2023 Nov 08
1
c(NA, 0+1i) not the same as c(as.complex(NA), 0+1i)?
...er, how I should read code like c(x, y) generally. Till > > now, I have thought of it like 'c(x, y)' is c(as(x, typeof(y)), y)` when > > "type(y) > type(x)". Basically in my mind, "coercion" in R <-> > > as.<newtype>(.) (or coerceVector() in C). > > > So I tracked down the source (which admittedly has been this way for much > > longer than the present discussion) to see what exactly c() is doing in > > this case: > > >https://github.com/r-devel/r-svn/blob/71e7480b07767f3b7d5c45a4...
2023 Nov 09
1
c(NA, 0+1i) not the same as c(as.complex(NA), 0+1i)?
...should read code like c(x, y) generally. Till >> > now, I have thought of it like 'c(x, y)' is c(as(x, typeof(y)), y)` when >> > "type(y) > type(x)". Basically in my mind, "coercion" in R <-> >> > as.<newtype>(.) (or coerceVector() in C). >> >> > So I tracked down the source (which admittedly has been this way for much >> > longer than the present discussion) to see what exactly c() is doing in >> > this case: >> >> >https://github.com/r-devel/r-svn/b...
2004 Feb 18
0
return a list of vectors from C?
...of the values rather than just the */ /* optimal values. It should return the optimization info as */ /* well as the residual values from the flikam function */ SEXP testfunc2( SEXP *pq, SEXP *obs ) { int i; double *pq_vect; double *obs_vect; SEXP ret_val; PROTECT( pq = coerceVector( pq, REALSXP ) ); PROTECT( obs = coerceVector( obs, REALSXP ) ); pq_vect = REAL( pq ); obs_vect = REAL( obs ); /* call my functions for the results */ /* generate the output list */ PROTECT( ret_val = allocVector( VECSXP, NPQ ) ); for( i = 0; i < NPQ; i++ ) { /...
2004 Feb 18
0
return a list of vectors from C?
...of the values rather than just the */ /* optimal values. It should return the optimization info as */ /* well as the residual values from the flikam function */ SEXP testfunc2( SEXP *pq, SEXP *obs ) { int i; double *pq_vect; double *obs_vect; SEXP ret_val; PROTECT( pq = coerceVector( pq, REALSXP ) ); PROTECT( obs = coerceVector( obs, REALSXP ) ); pq_vect = REAL( pq ); obs_vect = REAL( obs ); /* call my functions for the results */ /* generate the output list */ PROTECT( ret_val = allocVector( VECSXP, NPQ ) ); for( i = 0; i < NPQ; i++ ) { /...