search for: string_elt

Displaying 20 results from an estimated 122 matches for "string_elt".

2007 Jul 23
1
CHAR(STRING_ELT( - OK but CHAR(asChar(STRING_ELT( - not, why?
Any idea why CHAR(asChar(STRING_ELT( produces NA whereas CHAR(STRING_ELT( gets a pointer to a string? It's generally expected that STRING_ELT should already be a character, but why the coercion does not work? Here is a simple example (consistent over R2.5.1-R2.6 rev 42284, I didn't check earlier versions, but it used to be di...
2010 Feb 22
1
shash in unique.c
...tself 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) { if (STRING_ELT(x,indx) == NA_STRING) return 0; return scatter((unsigned int) (STRING_ELT(x,indx), d); } rather than its current form which appears to hash the string it points to : static int shash(SEXP x, int indx, HashData *d) { unsigned int k; const char *p; if(d->useUTF8) p = translateCh...
2010 Jun 19
1
more powerful iconv
..."), "from"); if(!isString(CADDR(args)) || length(CADDR(args)) != 1) error(_("invalid '%s' argument"), "to"); if(!isString(CADDDR(args)) || length(CADDDR(args)) != 1) error(_("invalid '%s' argument"), "sub"); - if(STRING_ELT(CADDDR(args), 0) == NA_STRING) sub = NULL; + if(STRING_ELT(CADDDR(args), 0) == NA_STRING || isRawx) sub = NULL; else sub = translateChar(STRING_ELT(CADDDR(args), 0)); mark = asLogical(CAD4R(args)); if(mark == NA_LOGICAL) @@ -584,7 +585,7 @@ PROTECT(ans = duplicate(x)); R_AllocStringBuffer...
2006 Oct 17
1
Error: STRING_ELT() can only be applied to a 'character vector', not a 'builtin'
...oad(system.file("data", paste(i, "RData", sep = "."), package = pkg), env) 2: g.data.load("tm.time", "hist.20051012") 3: g.inorder(93500, tm.time, 160000) aborting ... Segmentation fault Under R-2.4.0, it now gives this message: Error: STRING_ELT() can only be applied to a 'character vector', not a 'builtin' (which appears to be generated inside main/memory.c). I'm sorry I can't give a reproducible example, because it seems to happen randomly, and at different points in the process. So this is just a shot in the d...
2006 Jun 22
2
.Call and data frames
...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: SEXP colnames = getAttrib(df, R_NamesSymbol) cname = string(CHAR(STRING_ELT(colnames,i)) SEXP coldata = VECTOR_ELT(df,i) (data for i-th column) if(isReal(colData)) x = REAL(colData)[j]; else if(isInteger(colData)) i = INTEGER(colData)[j]; else if(isString(colData)) s = CHAR(STRING_ELT(colData,j)) The problem is that the last test (isString) never passes, even...
2010 May 21
1
Error in FUN(X[[1L]], ...) : STRING_ELT() can only be applied to a 'character vector', not a 'integer'
I am receiving this error running a command on a multi-row data-frame. The data is strings of text (each with new line separator, no spaces, no numerical characters). Error in FUN(X[[1L]], ...) : STRING_ELT() can only be applied to a 'character vector', not a 'integer' I can run single text string into the same command, and so the issue seems to be how the package deals with the second row - but I can't work out quite where the deficit is. If anybody has spotted this error befor...
2007 Feb 20
2
Problem with types on 64-bit
...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( v_dta_start, 0 ) != R_NilValue ) { dta.start = CHAR( STRING_ELT( v_dta_start, 0 ) ); } Yet on a 64-bit machine I get the following errors: (1) when I pass NULL it goes into the if clause and then when it tries to set dta.start it displays: CHAR() can only be applied to a 'CHARSXP', n...
2024 Mar 01
2
dput(..., file = stderr())
Curious to know if this warning is expected behavior, and if so, what is the recommended way instead: > dput(letters, file = stderr()) c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",
2003 Dec 17
1
Accessing row and col names of SEXP objects
...ough 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++) { printf("%s\n",CHAR(STRING_ELT(GetColNames(ts), j))); printf("%s\n",CHAR(VECTOR_ELT(GetColNames(ts), j))); printf("%s\n",CHARACTER_DATA(STRING_ELT(GetColNames(ts), j))); printf("%s\n",CHARACTER_DATA(VECTOR_ELT(GetColNames(ts), j))); } } Here is the object I'm passing in: tmp <- matr...
2004 Nov 29
1
data is getting corrupted
...ct SAMPLE_RECORD *sample_ptr; SEXP ans; PROTECT( filename = AS_CHARACTER( filename ) ); PROTECT(ans = allocVector(INTSXP, 1)); PROTECT( sample_in = AS_LIST( sample_in ) ); sample_ptr = build_sample_from_sexp( sample_in ); write_sample_to_file( &return_code, CHAR(STRING_ELT(filename, 0)), sample_ptr, N_SPECIES, SPECIES_PTR ); if( return_code != CONIFERS_SUCCESS ) { Rprintf( "unable to write %s\n", CHAR(STRING_ELT(filename, 0)) ); INTEGER(ans)[0] = -1; UNPROTECT(2); UNPROTECT( 1 ); return ans; } I...
2007 Sep 28
1
CHAR () and Rmpi
...onger be modified in place. This change allows compilers to warn or error about improper modification. Thanks to Herve Pages for the suggestion. ******* Unfortunately this causes Rmpi to fail since MPI requires char pointers rather than const char pointers. Normally I use CHAR(STRING_ELT((sexp_rdata),0)) to get the pointer to MPI where a R character vector (C sense) is stored. Because of the change, all character messengers fail. Is there an easy way to get a char pointer to STRING_ELT((sexp_rdata),0) and is also backward compatible to old R versions. BTW Rmpi does not do any modif...
2012 Dec 08
2
file.link on Windows 7
...k returns TRUE. I've checked the sources and .Internal calls "file.link", executing do_filelink(). The segment in file src/main/platform.c seems right, not mistaking argument 'from' for 'to': #ifdef Win32 wchar_t *from, *to; from = filenameToWchar(STRING_ELT(f1, i%n1), TRUE); to = filenameToWchar(STRING_ELT(f2, i%n2), TRUE); LOGICAL(ans)[i] = CreateHardLinkW(to, from, NULL) != 0; if(!LOGICAL(ans)[i]) { warning(_("cannot link '%ls' to '%ls', reason '%s'"), from, to, forma...
2007 Sep 13
1
chartr better
...or(_("invalid multibyte string 'old'")); wc = (wchar_t *) R_AllocStringBuffer((nc+1)*sizeof(wchar_t), &cbuff); mbstowcs(wc, s, nc + 1); + wtr_build_spec(wc, trs_cnt); /* use count only */ wtr_build_spec(wc, trs_old); s = translateChar(STRING_ELT(_new, 0)); @@ -2096,38 +2111,54 @@ /* Initialize the pointers for walking through the old and new wtr_spec lists and retrieving the next chars from the lists. */ + trs_cnt_ptr = Calloc(1, struct wtr_spec *); + *trs_cnt_ptr = trs_cnt->next; + for(...
2000 Aug 09
2
GenGC changes
...r code was written in a style like. VECTOR(dimnames)[0] = getAttrib(x, R_NamesSymbol); but that is no longer allowed. The functions `VECTOR_ELT' and `SET_VECTOR_ELT' must now be used to access and set elements of a generic vector. There are analogous functions `STRING_ELT' and `SET_STRING_ELT' for character vectors. To convert existing code, use the following replacements. original replacement `foo = VECTOR(bar)[i]' `foo = VECTOR_ELT(bar, i)' `VECTOR(foo)[j] = bar' `SET_VECTOR_EL...
2005 Aug 05
1
Installation problem on SGI IRIX6.5
...I. -I../../src/include -I../../src/include -I/user_data2/jfxiao/local/include -DHAVE_CONFIG_H -OPT:IEEE_NaN_inf=ON -g -c character.c -o character.o cc-1185 cc: WARNING File = character.c, Line = 714 An enumerated type is mixed with another type. warn = warn | !utf8strIsASCII(CHAR(STRING_ELT(CAR(args), i))); ^ cc-1552 cc: WARNING File = character.c, Line = 698 The variable "uclass" is set but never used. int i, len, minlen, uclass; ^ cc-1020 cc: ERROR File = character.c, Line = 1300 The identifier "wctrans_t&qu...
2013 Jan 11
1
Patch for setwd() to show path in error message
...nnot change working directory to 'path/that/fails/' PATCH: % diff -u util.c "util,patch.c" --- util.c 2012-12-16 13:13:05.002249900 -0800 +++ util,patch.c 2013-01-11 11:52:16.843236400 -0800 @@ -696,14 +696,14 @@ { const wchar_t *path = filenameToWchar(STRING_ELT(s, 0), TRUE); if(_wchdir(path) < 0) - error(_("cannot change working directory")); + error(_("cannot change working directory to '%s'"), path); } #else { const char *path = R_ExpandFileName(translateChar(STRING_...
2005 Jul 15
3
Passing character strings from C code to R
...t[i] = data[i]; 4 Free(data); 5 i=1; 6 if (comment) { // comment was found 7 n = strlen(comment); 8 if(n>0) { // and it actually have some length 9 Rprintf(" '%s' %i\n", comment, n); 10 PROTECT(Str = allocString(n+1)); 11 str = CHAR(STRING_ELT(Str, 0)); 12 strcpy(str, comment); 13 Rprintf(" '%s' %i\n", str, n); 14 setAttrib(Ret, install("comm"), Str); 15 i=2; 16 } 17 Free(comment); 18 } 20 UNPROTECT(i); Print statement in line 9 gives right results, but program cr...
2005 Jul 15
3
Passing character strings from C code to R
...t[i] = data[i]; 4 Free(data); 5 i=1; 6 if (comment) { // comment was found 7 n = strlen(comment); 8 if(n>0) { // and it actually have some length 9 Rprintf(" '%s' %i\n", comment, n); 10 PROTECT(Str = allocString(n+1)); 11 str = CHAR(STRING_ELT(Str, 0)); 12 strcpy(str, comment); 13 Rprintf(" '%s' %i\n", str, n); 14 setAttrib(Ret, install("comm"), Str); 15 i=2; 16 } 17 Free(comment); 18 } 20 UNPROTECT(i); Print statement in line 9 gives right results, but program cr...
2009 Jan 05
1
can't get names of R_env
...led printNames that looks like ----------------------- void printNames(SEXP list){ SEXP names = getAttrib(list, R_NamesSymbol); int i; Rprintf("List is of length:%d\n",length(list)); for (i = 0; i < length(list); i++) Rprintf("name of id:%d\t%s\n",i,CHAR(STRING_ELT(names, i))); } ----------------------- This is basicly just a copy of ----------------------- static SEXP getListElement(SEXP list, char *str) { SEXP elmt = R_NilValue, names = getAttrib(list, R_NamesSymbol); int i; for (i = 0; i < length(list); i++) if (strcmp(CHAR(STRING_ELT(name...
2011 Mar 18
1
[Patch suggestion] Adding 3rd arg to tempfile() to set extension
...nal and defaults to "" so no test for vector*/ + if (n3 != 1) + error(_("only single argument for end-of-filename pattern supported")); slen = (n1 > n2) ? n1 : n2; PROTECT(ans = allocVector(STRSXP, slen)); for(i = 0; i < slen; i++) { tn = translateChar( STRING_ELT( pattern , i%n1 ) ); td = translateChar( STRING_ELT( tempdir , i%n2 ) ); + te = translateChar( STRING_ELT( fileext , 0 ) ); /* try to get a new file name */ tm = R_tmpnam(tn, td); - SET_STRING_ELT(ans, i, mkChar(tm)); + if (0 != strlen(te)) { + /* append optional extension, or null string...