Displaying 20 results from an estimated 2000 matches similar to: "More questions about R extension programming"
2013 Jun 27
3
Read a text file into R with .Call()
Hi,
I want to read a text file into R with .Call().
So I define some NEW_CHARACTER() to store the chracters read and use SET_STRING_ELT to fill the elements.
e.g.
PROTECT(qNames = NEW_CHARACTER(10000));
char *foo; // This foo holds the string I want.
while(foo = readLine(FN)){
SET_STRING_ELT(qNames, i, mkChar(foo)));
}
In this way, I can get the desired character from qNames. The only problem
2003 Dec 17
1
Accessing row and col names of SEXP objects
Can someone lend me a hand with extracting the dimnames from a SEXP? I've
looked through R-exts, but I couldn't find an example.
Here is the code I'm using to grab the jth column name and print it, but the
colnames I'm getting are garbage.
None of the following are working.
void printInfo(SEXP ts) {
int j;
for (j=0; j<col; j++) {
2005 Jul 15
3
Passing character strings from C code to R
Hi,
I have a C code which produces array of integers and potentially a string,
and I have problems passing the string out. Here is the relevant part of the
code:
1 PROTECT(Ret = allocVector(INTSXP, n));
2 ret = (int*) INTEGER(Ret); /* get pointer to R's Ret */
3 for(i=0; i<n; i++) ret[i] = data[i];
4 Free(data);
5 i=1;
6 if (comment) { // comment was found
7 n
2005 Jul 15
3
Passing character strings from C code to R
Hi,
I have a C code which produces array of integers and potentially a string,
and I have problems passing the string out. Here is the relevant part of the
code:
1 PROTECT(Ret = allocVector(INTSXP, n));
2 ret = (int*) INTEGER(Ret); /* get pointer to R's Ret */
3 for(i=0; i<n; i++) ret[i] = data[i];
4 Free(data);
5 i=1;
6 if (comment) { // comment was found
7 n
2007 Jan 23
2
is it necessary to always register C routines with R_registerRoutines?
I am writing bindings to the neural network simulator SNNS.
At present I have used only .C interface, now I'm studying .Call interface.
I have adapted the example from page 77 of r-exts.pdf, however, it crashes
R.
I use MingW as recommended by Duncan Murdoch.
Please, tell me what I am missing.
The code is below.
Thank you.
SEXP snns_getVersion(void)
{SEXP version;
char *v;
2007 Feb 20
2
Problem with types on 64-bit
Hi Everyone,
I have a problem using some working 32-bit R code with 64-bit machine ( I am
using version R-2.4.1 ). The problem occurs when I am trying to detect a NULL
STRSXP type. ( Perhaps I am doing this detection in the wrong way? )
On 32-bit the following works, and correctly identifies if I am passing NULL
or a valid string object:
if ( v_dta_start != R_NilValue && STRING_ELT(
2008 Jan 29
2
Problem with new("externalptr")
Hi,
It seems that new("externalptr") is always returning the same instance, and
not a new one as one would expect from a call to new(). Of course this is hard
to observe:
> new("externalptr")
<pointer: (nil)>
> new("externalptr")
<pointer: (nil)>
since not a lot of details are displayed.
For example, it's easy to see that 2
2001 Dec 19
2
R strings from C
Hi,
I am trying to study R internal behaviour. So long, I have not
succeeded to access the value of R strings from C.
I use:
void salvesta_tabel(
SEXP data_frame,
SEXP file
)
{
printf( "nimi %d\n", (R_CHAR)( file));
}
and from the R side:
salvesta.tabel <-
function (x, file = "") {
.Call( "salvesta_tabel", x, file)
}
When calling
2011 Mar 18
1
[Patch suggestion] Adding 3rd arg to tempfile() to set extension
The other day I was working on an example which used tempfile() to create
file for use by the graphics device. And while I love tempfile()---as it is
portable and clever and the files get cleaned by R and all that---I noticed
one missing feature I would like to see: beside a starting name pattern, and
an optional directory, an 'file extension' argument would be nice to have.
As e.g. in
2003 Dec 12
3
C++: Appending Values onto an R-Vector.
Hi folks. I posted this question a few days ago, but maybe it got lost
because of the code I included with it. I'm having a problem using the
SET_LENGTH() macro in an R extension I'm writing in C++. In a function
within the extension I use SET_LENGTH() to resize R vectors so as to
allow the concatenation of single values onto the vectors -- it's a
"push back" function to
2007 Sep 13
1
chartr better
For example, the following changes are necessary when i convert a
Japanese hiragana into katakana in chattr.
R code:
> chartr("\u3041-\u3093","\u30a1-\u30f3","\u3084\u3063\u305f\u30fc")
--- R-alpha.orig/src/main/character.c 2007-09-05 07:13:27.000000000 +0900
+++ R-alpha/src/main/character.c 2007-09-13 16:10:21.000000000 +0900
@@ -2041,6 +2041,16 @@
2010 Jun 19
1
more powerful iconv
R community,
As you may know, R's iconv doesn't work well converting to and from
encodings that allow embedded nulls. For example
> iconv("foo", to="UTF-16")
Error in iconv("foo", to = "UTF-16") :
embedded nul in string: '\xff\xfef\0o\0o\0'
However, I don't believe embedded nulls are at issue here, but rather
that R's iconv
2007 Jan 19
5
Problem with C extension
Hello,
I try to write an extension in C, to get a faster functions.
Therefore I have to add an element (vector) to a vector. The command in
R is very simple: x = c(x,a)
But in C I have the problem to reallocate my vector for getting more
space. Everything I tried, I get a "Segmentation fault".
So, how can I combine two vectors in C and give the result back to R
(return(x))?
Thanks
2010 Feb 22
1
shash in unique.c
Looking at shash in unique.c, from R-2.10.1 I'm wondering if it makes sense
to hash the pointer itself rather than the string it points to?
In other words could the SEXP pointer be cast to unsigned int and the usual
scatter be called on that as if it were integer?
shash would look like a slightly modified version of ihash like this :
static int shash(SEXP x, int indx, HashData *d)
{
2004 Mar 06
2
.Call: is new attribute of protected object auto-protected
Hi,
I have an SEXP obj in a C function called via .Call(). The obj is
protected (in fact it is an argument to .Call and therefore
automatically protected). If I set an attribute of obj does the
attribute become protected too? Here is an example
SEXP foo(SEXP obj) {
SET_NAMES(obj, NEW_CHARACTER(3)); /* are names protected or not? */
...
}
Thanks,
Vadim
[[alternative HTML version
2009 Sep 16
2
I want to get a reference to this time series object
I'm trying to get a reference to this object in C
SWX.RET[1:6,c("SBI,"SPI","SII")]
While i am able to access and use a plain SWX.RET object, I'm getting
confused on how to create an object with the array subscripts like above.
Here is what I tried to do. It doesn't work because "[" is obviously not an
operation or function on SWX.RET. So how do I
2006 Aug 21
1
return tree from .Call
Hello:
I was hoping to get some advice about how to return a tree (basically a
linked list -- with each node containing a parent, left, and right node
pointers) from a C routine back into R. Each node itself contains several
attributes (a double, a char *, an int, and a void * )
Initially I was thinking I could just return to R a SEXP containing a
pointer to the Root Node, but then realized
2006 Jun 22
2
.Call and data frames
Hello,
I'm trying to fetch a data frame through the C API,
and have no problem doing this when all columns
are numbers, but when there is a column of
strings I have a problem. On the C-side the
function looks like:
SEXP myfunc(SEXP df),
and it is called with a dataframe from
the R side with:
.Call("myfunc", somedataframe)
On the C side (actually C++ side) I use code
like this:
2023 Jan 31
1
Sys.getenv(): Error in substring(x, m + 1L) : invalid multibyte string at '<ff>' if an environment variable contains \xFF
Can we use the "bytes" encoding for such environment variables invalid
in the current locale? The following patch preserves CE_NATIVE for
strings valid in the current UTF-8 or multibyte locale (or
non-multibyte strings) but sets CE_BYTES for those that are invalid:
Index: src/main/sysutils.c
===================================================================
--- src/main/sysutils.c
2010 Nov 15
1
SEXP and slots
Hello,
Since people have whisperred about Rcpp, I'd like to play too.
> On 11/15/2010 07:45 AM, Patrick Leyshock wrote:
>> Very helpful, thank you.
>>
>> A couple other questions, please:
>>
>> 1. I've got a function written in C, named "my_c_function". In my R
>> code I call this function, passing to it an INTSXP and a STRSXP,
>>