Displaying 20 results from an estimated 35 matches for "r_namessymbol".
2003 May 09
4
getAttr problem
Hi all,
It seems that getAttr doesn't return "names" attribute properly as in
getAttrib(x, R_NamesSymbol));
If you look at section 4.7.4 in "Writing R Extensions", the second example of
SEXP out(SEXP, SEXP) returns NULL for the names attribute of the
outer product.
This is true for R 1.7.0 on both Win2000 with mingw and Redhat 9.0 with gcc.
Is there something I am missing?
Best,
Tsveta...
2006 Mar 27
1
Safe to UNPROTECT() when object is assigned to a list?
...cVector(INTSXP, 2));
INTEGER(dim)[0] = nx; INTEGER(dim)[1] = ny;
setAttrib(ans, R_DimSymbol, dim);
*** It is safe to do UNPROTECT(1) for 'dim' already here, correct? ***
PROTECT(dimnames = allocVector(VECSXP, 2));
SET_VECTOR_ELT(dimnames, 0, getAttrib(x, R_NamesSymbol));
SET_VECTOR_ELT(dimnames, 1, getAttrib(y, R_NamesSymbol));
setAttrib(ans, R_DimNamesSymbol, dimnames);
UNPROTECT(3);
return(ans);
}
Thanks
/Henrik
2009 Jan 05
1
can't get names of R_env
...ULL or a VECSXP). A frame is a tagged pairlist with tag the symbol
and CAR the bound value."
But I'm having troubles accessing the data.
I've written a small function called 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 getListEleme...
2009 Mar 30
1
Setting the names attribute of a list?
Hello,
I have created a vector with 2 elements(see code below)
I am calling this function many thousands of times (hundreds of
thousands) after some time
i get
*** caught segfault ***
address 0x5, cause 'memory not mapped'
However, if i dont set the R_NamesSymbol, I do not get any such error.
Am I doing this correctly?
Thank you
Saptarshi
==CODE===
// kxp and usar are two SEXP's which have not been protected
SEXP res
PROTECT(res);
res= allocVector(VECSXP, 2);
SET_VECTOR_ELT(res,0,kxp);
SET_VECTOR_ELT(res,1,usar);
names=allocVector(VECSXP,2);PROTECT(...
2005 Nov 07
3
R thread safe
...omp_unset_lock(&lck);
/* do computational kernel in parallel */
alocal = eval(expr, rho);
omp_set_lock(&lck);
SET_VECTOR_ELT(ans, i, alocal);
UNPROTECT(1);
omp_unset_lock(&lck);
}
setAttrib(ans, R_NamesSymbol, getAttrib(list, R_NamesSymbol));
UNPROTECT(1);
return(ans);
}
***********
The code works fine using one thread and breaks currently down with 2 threads.
I am using a recent R distribution and the complete R code is compile with
"-openmp" and the Pathscale compiler suite...
2014 Jun 24
2
using C code to create data frame but always return as list
...lue_t* onesymbol;
if (jl_is_array(ret))
{
PROTECT(names=allocVector(STRSXP,collen));
for (i=0;i<jl_array_len(ret);i++)
{
onesymbol=jl_arrayref((jl_array_t*)ret,i);
if (jl_is_symbol(onesymbol))
SET_STRING_ELT(names,i,mkChar(((jl_sym_t*)onesymbol)->name));
}
setAttrib(ans,R_NamesSymbol,names);
UNPROTECT(1);
}
//set row names
sprintf(evalcmd,"size(%s,1)",dfname);
jl_value_t* rows=jl_eval_string(evalcmd);
int rowlen=jl_unbox_long(rows);
PROTECT(rownames=allocVector(INTSXP,rowlen));
for (i=0;i<rowlen;i++)
INTEGER(rownames)[i]=i+1;
setAttrib(ans,R_RowNamesSy...
2006 Jun 22
2
.Call and data frames
...t 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:
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 te...
1999 May 11
1
another multivariate ts bug
I think this is another one of the same kind of bugs in ts:
Version 0.64.1 (May 8, 1999)
...
> z <- ts(matrix(1:20,10,2), start=c(1969,1), frequency=12)
> (z > 5) | (z < 2)
Error: invalid time series parameters specified
>
Paul
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read
2006 Oct 15
1
Feature request: names(someEnv) same as ls(someEnv)
Hi,
I would be nice if names() returned the equivalent of ls() for
environments.
--- a/src/main/attrib.c
+++ b/src/main/attrib.c
@@ -687,6 +687,8 @@ SEXP attribute_hidden do_names(SEXP call
s = CAR(args);
if (isVector(s) || isList(s) || isLanguage(s))
return getAttrib(s, R_NamesSymbol);
+ if (isEnvironment(s))
+ return R_lsInternal(s, 0);
return R_NilValue;
}
+ seth
--
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
http://bioconductor.org
2014 Mar 06
1
Create dataframe in C from table and return to R
...snm = allocVector(STRSXP,2));
SET_STRING_ELT(lsnm,0,mkChar("int"));
SET_STRING_ELT(lsnm,1,mkChar("string"));
for ( i = 0 ; i < 3; i++ ) {
SET_STRING_ELT(dfStr,i,mkChar(ab[i]));
INTEGER(dfint)[i] = sn[i];
}
SET_VECTOR_ELT(df,0,dfint);
SET_VECTOR_ELT(df,1,dfStr);
setAttrib(df,R_NamesSymbol,lsnm);
//PROTECT(dfm=LCONS(dfm,list3(dfm,R_MissingArg,mkFalse())));
UNPROTECT(4);
dfm = PROTECT(lang2(install("data.frame"),df));
SEXP res = PROTECT(eval(dfm,R_GlobalEnv));
UNPROTECT(2)
}
------------------------------------------------------------------------
It works fine but i wan...
2000 Jul 12
1
getAttrib() and setAttrib()
...tmp = REAL(x)[i];
for(j = 0; j < ny; j++)
REAL(ans)[i + nx*j] = tmp * REAL(y)[j];
}
PROTECT(dim = allocVector(INTSXP, 2));
INTEGER(dim)[0] = nx; INTEGER(dim)[1] = ny;
// setAttrib(ans, R_DimSymbol, dim);
PROTECT(dimnames = allocVector(VECSXP, 2));
// VECTOR(dimnames)[0] = getAttrib(x, R_NamesSymbol);
// VECTOR(dimnames)[1] = getAttrib(y, R_NamesSymbol);
// setAttrib(ans, R_DimNamesSymbol, dimnames);
UNPROTECT(3);
return(ans);
}
Here is the output, a vector:
> out(c(1,2),c(3,4))
[1] 3 6 4 8
But when I uncomment any one of the 4 lines which use getAttrib() or
setAttrib(), R crashes f...
2005 Nov 07
4
Time-measurement in milliseconds
Hi there
I'm loking for a time-measurement to measure time-differences in
milliseconds.
On my search, I only found the following:
- package "base": Sys.time()
-> only second-accuracy
- package "R.utils": System$currentTimeMillis()
-> returns integer of milliseconds, but accuracy is only whole
seconds too.
At the moment I run every bit of code to measure
2013 Dec 16
1
External pointers and changing SEXPTYPE
...or(STRSXP, efldNR ));
for( ix = 0; ix < efldNR; ix++ )
SET_STRING_ELT(mydata->ans_nms, ix, mkChar(vnames[ix]));
// later I bind values of non-R variables from my data structure to a
proper vector
PROTECT(mydata->ans = Rf_allocVector(VECSXP, efldNR ));
Rf_setAttrib(mydata->ans, R_NamesSymbol, mytraj->ans_nms);
SET_VECTOR_ELT(mydata->ans, 0, mydata->R_a );
SET_VECTOR_ELT(mydata->ans, 1, mydata->R_b );
...
// all protects get unprotected before return
// finalizer is registered as well
return Rdata;
Later on in read_my_data() I read the pointer:
my_data_ptr...
2000 Aug 09
2
GenGC changes
...a new `generational' garbage collector which means that
strings and vectors (and language objects) are handled differently from
the numerical atomic types.
>From ``Writing R Extensions'':
Earlier 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 exis...
2003 Jun 06
1
Problerm building R-1.7.0 on OpenBSD3.2/sparc64
...s'
/home/test/proj/downl/R-1.7.0/bin/R.bin: /home/test/proj/downl/R-1.7.0/library/m
ethods/libs/methods.so: can't resolve reference 'R_GlobalEnv'
/home/test/proj/downl/R-1.7.0/bin/R.bin: /home/test/proj/downl/R-1.7.0/library/m
ethods/libs/methods.so: can't resolve reference 'R_NamesSymbol'
/home/test/proj/downl/R-1.7.0/bin/R.bin: /home/test/proj/downl/R-1.7.0/library/m
ethods/libs/methods.so: can't resolve reference 'R_MissingArg'
/home/test/proj/downl/R-1.7.0/bin/R.bin: /home/test/proj/downl/R-1.7.0/library/m
ethods/libs/methods.so: can't resolve reference '...
2003 Sep 05
1
Problem with S4 slots in C code (PR#4073)
...SET_STRING_ELT(names, 0, mkChar("age"));
SET_STRING_ELT(names, 1, mkChar("year"));
SET_STRING_ELT(names, 2, mkChar("sex"));
SET_STRING_ELT(names, 3, mkChar("season"));
SET_STRING_ELT(names, 4, mkChar("area"));
setAttrib(dimnames, R_NamesSymbol, names);
setAttrib(v, R_DimNamesSymbol, dimnames);
//Set data
REAL(v)[0] = 2;
//Set slot
SET_SLOT(FLQuant, install(".Data"), v);
UNPROTECT(10);
return FLQuant;
}
--please do not edit the information below--
Version:
platform...
2012 Dec 10
1
Changing arguments inside .Call. Wise to encourage "const" on all arguments?
...ur before this is called. */
SEXP DropDims(SEXP x)
{
SEXP dims, dimnames, newnames = R_NilValue;
int i, n, ndims;
PROTECT(x);
dims = getAttrib(x, R_DimSymbol);
[... SNIP ....]
setAttrib(x, R_DimNamesSymbol, R_NilValue);
setAttrib(x, R_DimSymbol, R_NilValue);
setAttrib(x, R_NamesSymbol, newnames);
[... SNIP ....]
return x;
}
Well, at least there's a warning comment with that one. But it does
show .Call allows call by reference.
Why allow it, though? DropDims could copy x, modify the copy, and return it.
I wondered why DropDims bothers to return x at all. We seem to be
us...
2003 May 05
1
segfault when applying strange coercion (PR#2923)
I made a mistake -- and R crashed. A (more or less) reproducible example
seems to be:
x <- matrix(nrow=20000, ncol=20)
x$any <- numeric(0)
It is possible to crash R by executing these lines several times (1 -
20) on Windows as well as on Solaris (might be related to PR#2880 -
let's call it "non-existing list elements")
Uwe Ligges
--please do not edit the
2014 Apr 03
1
question regarding lang2 command in C
Hi ,
I am asking too many questions , sorry for that . I am creating a data
frame in C itself , reading a table .
The data frame calling code looks like this
======================================
*PROTECT(dfm=lang2(install("data.frame"),df));*
*SEXP res = PROTECT(eval(dfm,R_GlobalEnv));*
UNPROTECT(2);
return res;
==================================
It works fine , now the problem
2010 Sep 08
0
Correction to vec-subset speed patch
...attribute (a vector list) of the generated subscript vector */
- newnames = getAttrib(indx, R_UseNamesSymbol);
- if (newnames != R_NilValue) {
+ if (TYPEOF(s)==STRSXP &&
+ (newnames = getAttrib(indx, R_UseNamesSymbol)) != R_NilValue) {
SEXP oldnames = getAttrib(x, R_NamesSymbol);
if (oldnames != R_NilValue) {
for (i = 0; i < n; i++) {
@@ -1195,7 +1195,7 @@
error(_("invalid number of subscripts to list assign"));
PROTECT(sub = GetOneIndex(sub, ind));
- PROTECT(indx = makeSubscript(x, sub, &stretch, R_NilValue));
+ PROTECT(indx = make...