[R] [R-pkgs] Rcpp11 3.1.0 is on CRAN.
Hello, R version 3.1.0 was released yesterday, and as always is welcome with great pleasure. One of the features that is of particular interest to me is the support for C++11. I would encourage you to read [Writing R Extensions](http://cran.r-project.org/doc/manuals/r-devel/R-exts.html#Using-C_002b_002b11-code) to familiarize yourself with what this supports means and how to take advantage of it. C++11 is a major upgrade of the C++ standard, making C++ more expressive, more efficient, more fun to use and teach. It almost feels like a new language if you embrace it fully. The standards committee has done a great job of maintaining compatibility, which means that code written with older standard will still compile and work. However, with C++11 code you write today and tomorrow will not be the same as code you used to write with C++98. To get the best of what C++11 has to offer, I'm releasing Rcpp11 today. Rcpp11 is a complete redesign of Rcpp, focused on C++11. Rcpp11 is a header only C++ library, distributed as an R package on CRAN, that facilitates embedding C++ code in R packages. I'll try to keep this announcement short. More details will follow on dedicated channels. I will just highlight a few aspects of Rcpp11 that are high level enough for such an annoucement. Header Only === Rcpp11 is header only -- it consists only of a set of `.h` files. Rcpp11 has no `.cpp` files, and no R functions. This eliminates many problems inherent to binary compatibility that Rcpp has been fighting with for years. The recommended way to use Rcpp11 is to have these lines in the `DESCRIPTION` file of your package: ``` LinkingTo: Rcpp11 SystemRequirements: C++11 ``` Modernized code base Many features of the original Rcpp code base are the consequence of my learning C++ and the internal API of R. After a few years of experience, I can now admit that mistakes were made while designing it. Unfortunately for reasons outside of my control, it is not possible to fix these mistakes under the umbrella of the Rcpp package. Things are radically different for Rcpp11, which I will maintain. Over the past few months, I have considered many features of the code base and either decided to abandon them or upgrade them to the level of expectation we should have for a modern R/C++ interface. API --- Most of what is usually called the API has been retained. I do not guarantee low level compatibililty, but there is conceptual compatibility. For example, Rcpp11 contains all the classes we would expect: `NumericVector`, `List`, ... I'm not going into details about what the individual differences are. Instead I will start documenting how to use the API provided by Rcpp11. Attributes -- Attributes is probably the best feature that has ever been contributed to Rcpp. It gives a mechanism for decorating C++ functions, parsing these decorations and generating scaffolding code around them. This feature has not been retained in Rcpp11, but instead has been moved into a new package called [attributes](https://github.com/Rcpp11/attributes), which is being developed and will be released later. It is worth mentioning that code generated by Rcpp's `compileAttributes` function should be compilable against Rcpp11. When attributes becomes available it will provide a more flexible approach, and provide facilities for package authors to implement and use their own attributes. Modules --- Rcpp modules was not retained as part of Rcpp11. This was a hard decision, because I invested a lot of time developing the original code behind Rcpp modules. However modules have significant problems which make them hard to maintain. Modules are also very demanding on the compiler. However, I still believe that the promise of Rcpp modules -- exposing C++ classes at the R level -- is very worthwhile. My plan is to redesign it using a different approach, more oriented towards code generation, à la attributes. Time and Date classes - I decided to abandon the classes responsible to handling dates and times. Better classes might be introduced when I'm comfortable with the design. Design documents and pull requests are welcome. Further discussion == Please consider subscribing to the R and C++ mailing list that was created a few days ago: https://groups.google.com/forum/#!forum/r-and-cpp The scope of the mailing list is broader, the intention is to discuss all things R and C++. Questions about Rcpp11, Rcpp or anything related to using C++ and R are welcome. As of today, 37 participants are registered. Please consider replying to this annoucement email through the mailing list. Rcpp11 is developed through the Rcpp11 organisation on github. Feel free to report issues and submit pull requests. https://github.com/Rcpp11/Rcpp11 Versioning == The pattern that has been decided for versions of Rcpp11 is to use
Re: [R] simple payoff function
Le 11/12/10 16:09, Santosh Srinivas a écrit : Just wondering if there is a better way to do this? x- seq(4,20,1) y- sapply(x, function(x) (max(x-10,0))) Is there a easier way to get to y? i.e. max(x-10,0) Hello, You are probably looking for pmax, that is described in the same help page as max. pmax(x-10, 0) [1] 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 ?pmax Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/fT2rZM : highlight 0.2-5 |- http://bit.ly/gpCSpH : Evolution of Rcpp code size `- http://bit.ly/hovakS : RcppGSL initial release __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error using Rcpp under windows xp
Hello randomcz, Thank you for your interrest in Rcpp. Rcpp has its own mailing list. http://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel Please subscribe and report your question there. People will be happy to help you. Romain Le 03/12/10 03:57, randomcz a écrit : Hi, I am a newbie to Rcpp packages, and got problems in having basic set-ups for Rcpp under windows xp. Here is the list I have done. 1) installed Rtools and have no problem in compiling .c file. 2) installed Rcpp packages 3) set enviroment variables 'path' to make C:\Program Files\R\R-2.12.0\library\Rcpp\include\ searchable The sample C++ code I used is from the original website: http://dirk.eddelbuettel.com/code/rcpp.examples.html #includeRcpp.h RcppExport SEXP newRcppVectorExample(SEXP vector) { Rcpp::NumericVector orig(vector); // keep a copy (as the classic version does) Rcpp::NumericVector vec(orig.size()); // create a target vector of the same size // we could query size via // int n = vec.size(); // and loop over the vector, but using the STL is so much nicer // so we use a STL transform() algorithm on each element std::transform(orig.begin(), orig.end(), vec.begin(), sqrt); Rcpp::Pairlist res(Rcpp::Named( result, vec), Rcpp::Named( original, orig)); return res; } I got bunch of error messages like: test.o:test.cpp:(.test+0x141): undefined reference to 'RcppResultSet::RcppResultSet()' ... undefined reference to 'double* Rcpp::internal::r_vector_start14,double(SEXPREC*)' collect2: ld returned 1 exit status Can someone help me out? Thanks, -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/hovakS : RcppGSL initial release |- http://bit.ly/iaxTdO : parser 0.0-12 `- http://bit.ly/gnCl01 : Rcpp 0.8.9 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Strange problems with compiling dll
Hello, Your question is more appropriate on the R-devel mailing list. Le 03/12/10 00:41, Oleksandr Dyklevych a écrit : Dear sir\madam! I'm trying to speed up my R code by writing quite simple dll's in C. But I faced some problems, and I cannot determine their source. #include Rinternals.h SEXP mycombin(SEXP N, SEXP k){ int i, *j, *l, c; j = INTEGER(k);l = INTEGER(N); c = 1; if(j[0] 0 j[0] l[0]){ if(j[0] = l[0] - j[0]){ for(i = l[0]; i = l[0] - j[0] + 1; i--){ c = c * i / (l[0] - i + 1); } } else{ for(i = l[0]; i = j[0] + 1; i++){ c = c * i / (l[0] - i + 1); } } } return ScalarInteger(c); } But, when I try to compile it What does that mean ? What did you try ? R CMD SHLIB mycomin.c definitely works for me. What part of Writing R Extensions was not clear ? Romain I have 5 errors, and all of them come form linker and say next (Code::Blocks): ||=== mcb2, Release ===| obj\Release\conv.o:conv.c|| undefined reference to `INTEGER'| obj\Release\conv.o:conv.c|| undefined reference to `INTEGER'| obj\Release\conv.o:conv.c|| undefined reference to `Rf_ScalarInteger'| obj\Release\conv.o:conv.c|| undefined reference to `Rf_ScalarInteger'| obj\Release\conv.o:conv.c|| undefined reference to `Rf_ScalarInteger'| ||=== Build finished: 5 errors, 0 warnings ===| I found out that I need to link Rdll.lib, but to make it I should use these instructions make R.exp lib /def:R.exp /out:Rdll.lib but i cannot figure out where I should use them. I'm trying from here C:\Rtools\src\gnuwin32 but each time i get make: *** No rule to make target `R.exp'. Stop. So where should I state this rule and which rule?... Will you help me, please, to connect my C compiler to R? Best regards, Oleksandr -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/hovakS : RcppGSL initial release |- http://bit.ly/iaxTdO : parser 0.0-12 `- http://bit.ly/gnCl01 : Rcpp 0.8.9 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help: program efficiency
Hello, Someone pointed out to me off list about this construct: nodup_sort - function(x, fun = nodup3){ i - sort.list(x) x[i] - fun(x[i]) x } which deals more efficiently with the reordering. x - sample( 1:10, size = 30, replace = TRUE ) system.time( nodup_cpp( x ) ) utilisateur système écoulé 0.127 0.005 0.132 system.time( nodup_sort( x, nodup3 ) ) utilisateur système écoulé 0.287 0.009 0.295 system.time( nodup_sort( x, nodup3a ) ) utilisateur système écoulé 0.168 0.010 0.179 system.time( nodup_sort( x, nodup4 ) ) utilisateur système écoulé 0.157 0.005 0.163 system.time( nodup_sort( x, nodup_cpp_assumingsorted ) ) utilisateur système écoulé 0.096 0.001 0.097 So in this example, it seems more efficient to sort first and use the algorithm assuming that the data is sorted. There is probably a way to be smarter in nodup_cpp where the bottleneck is likely to be related to map::find. Another version taking some more internally : nodup_cpp_hybrid - cxxfunction( signature( x_ = numeric, sort_ = integer ), ' NumericVector input(x_) ; NumericVector x = cloneNumericVector( x_) ; IntegerVector sort( sort_ ) ; int n = x.size() ; double current, previous = input[ sort[0] - 1 ] ; double index = 0.0 ; int si ; for( int i=1; in; i++){ si = sort[i] - 1; current = input[ si ] ; if( current == previous ){ index += .01 ; x[ si ] = current + index ; } else { index = 0.0 ; } previous = current ; } return x ; ', plugin = Rcpp ) no big difference: system.time( res6 - nodup_cpp_hybrid( x, sort.list(x) ) ) utilisateur système écoulé 0.092 0.000 0.092 Profiling reveals this: Rprof() for(i in 1:100) { res6 - ( nodup_cpp_hybrid( x, sort.list(x) ) ) } Rprof(NULL) summaryRprof() $by.self self.time self.pct total.time total.pct sort.list6.5090.03 6.50 90.03 .Call0.42 5.82 0.42 5.82 file.exists 0.30 4.16 0.30 4.16 $by.total total.time total.pct self.time self.pct nodup_cpp_hybrid 7.22100.00 0.00 0.00 sort.list 6.50 90.03 6.5090.03 .Call 0.42 5.82 0.42 5.82 file.exists0.30 4.16 0.30 4.16 $sample.interval [1] 0.02 $sampling.time [1] 7.22 The 4.16 % taken by file.exists indicates that someone in the inline project has to do some work (on my TODO list). But otherwise sort.list dominates the time. Romain Le 26/11/10 21:22, Romain Francois a écrit : Le 26/11/10 21:13, Romain Francois a écrit : Hello, Can we really make the assumption that the data is sorted. The original example was not: I am working on a function to make a duplicated value unique. For example, the original vector would be like : a = c(2,1,1,3,3,3,4) If we can make the assumption, here is a C++ based version: nodup_cpp_assumingsorted - cxxfunction( signature( x_ = numeric ), ' // since we modify x, we need to make a copy NumericVector x = cloneNumericVector(x_); int n = x.size() ; double current, previous = x[0] ; int index ; for( int i=1; in; i++){ current = x[i] ; if( current == previous ){ x[i] = current + (++index) / 100.0 ; } else { index = 0 ; } previous = current ; } return x ; ', plugin = Rcpp ) with these results: x - sort( sample( 1:10, size = 30, replace = TRUE ) ) system.time( nodup3( x ) ) utilisateur système écoulé 0.090 0.004 0.094 system.time( nodup3a( x ) ) utilisateur système écoulé 0.036 0.005 0.040 system.time( nodup4( x ) ) utilisateur système écoulé 0.025 0.004 0.029 system.time( nodup_cpp_assumingsorted( x) ) utilisateur système écoulé 0.003 0.001 0.004 Now, if we don't make the assumption that the data is sorted, here is another C++ based version: require( inline ) require( Rcpp ) nodup_cpp - cxxfunction( signature( x_ = numeric ), ' // since we modify x, we need to make a copy NumericVector x = cloneNumericVector(x_); typedef std::mapdouble,int imap ; typedef imap::value_type pair ; imap index ; int n = x.size() ; double current, previous = x[0] ; index.insert( pair( previous, 0 ) ); imap::iterator it = index.begin() ; for( int i=1; in; i++){ current = x[i] ; if( current == previous ){ x[i] = current + ( ++(it-second) / 100.0 ) ; } else { it = index.find(current) ; if( it == index.end() ){ it = index.insert( current previous ? it : index.begin(), pair( current, 0 ) ) ; } else { x[i] = current + ( ++(it-second) / 100.0 ) ; } previous = current ; } } return x ; ', plugin = Rcpp ) which gives me this : x - sample( 1:10, size = 30, replace = TRUE ) system.time( nodup_cpp( x ) ) utilisateur système écoulé 0.111 0.002 0.113 system.time( nodup3( sort( x
Re: [R] help: program efficiency
% on that dataset. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of randomcz Sent: Thursday, November 25, 2010 6:49 AM To: r-help@r-project.org Subject: [R] help: program efficiency hey guys, I am working on a function to make a duplicated value unique. For example, the original vector would be like : a = c(2,1,1,3,3,3,4) I'll like to transform it into: a.nodup = 2, 1.01, 1.02, 3.01, 3.02, 3.03, 4 basically, find the duplicates and assign a unique value by adding a small amount and keep it in order. I come up with the following codes, but it runs slow if t is large. Is there a better way to do it? nodup = function(t) { t.index=0 t.dup=duplicated(t) for (i in 2:length(t)) { if (t.dup[i]==T) t.index=t.index+0.01 else t.index=0 t[i]=t[i]+t.index } return(t) } -- View this message in context: http://r.789695.n4.nabble.com/help-program-efficiency-tp305907 9p3059079.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/9VOd3l : ZAT! 2010 |- http://bit.ly/c6DzuX : Impressionnism with R `- http://bit.ly/czHPM7 : Rcpp Google tech talk on youtube __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help: program efficiency
Le 26/11/10 21:13, Romain Francois a écrit : Hello, Can we really make the assumption that the data is sorted. The original example was not: I am working on a function to make a duplicated value unique. For example, the original vector would be like : a = c(2,1,1,3,3,3,4) If we can make the assumption, here is a C++ based version: nodup_cpp_assumingsorted - cxxfunction( signature( x_ = numeric ), ' // since we modify x, we need to make a copy NumericVector x = cloneNumericVector(x_); int n = x.size() ; double current, previous = x[0] ; int index ; for( int i=1; in; i++){ current = x[i] ; if( current == previous ){ x[i] = current + (++index) / 100.0 ; } else { index = 0 ; } previous = current ; } return x ; ', plugin = Rcpp ) with these results: x - sort( sample( 1:10, size = 30, replace = TRUE ) ) system.time( nodup3( x ) ) utilisateur système écoulé 0.090 0.004 0.094 system.time( nodup3a( x ) ) utilisateur système écoulé 0.036 0.005 0.040 system.time( nodup4( x ) ) utilisateur système écoulé 0.025 0.004 0.029 system.time( nodup_cpp_assumingsorted( x) ) utilisateur système écoulé 0.003 0.001 0.004 Now, if we don't make the assumption that the data is sorted, here is another C++ based version: require( inline ) require( Rcpp ) nodup_cpp - cxxfunction( signature( x_ = numeric ), ' // since we modify x, we need to make a copy NumericVector x = cloneNumericVector(x_); typedef std::mapdouble,int imap ; typedef imap::value_type pair ; imap index ; int n = x.size() ; double current, previous = x[0] ; index.insert( pair( previous, 0 ) ); imap::iterator it = index.begin() ; for( int i=1; in; i++){ current = x[i] ; if( current == previous ){ x[i] = current + ( ++(it-second) / 100.0 ) ; } else { it = index.find(current) ; if( it == index.end() ){ it = index.insert( current previous ? it : index.begin(), pair( current, 0 ) ) ; } else { x[i] = current + ( ++(it-second) / 100.0 ) ; } previous = current ; } } return x ; ', plugin = Rcpp ) which gives me this : x - sample( 1:10, size = 30, replace = TRUE ) system.time( nodup_cpp( x ) ) utilisateur système écoulé 0.111 0.002 0.113 system.time( nodup3( sort( x ) ) ) utilisateur système écoulé 0.162 0.011 0.172 system.time( nodup3a( sort( x ) ) ) utilisateur système écoulé 0.099 0.009 0.109 system.time( nodup4( sort( x ) ) ) utilisateur système écoulé 0.089 0.004 0.094 so nodup4 is still faster, but the values are not in the right order: x - c( 2, 1, 1, 2 ) nodup4( sort( x ) ) [1] 1.00 1.01 2.00 2.01 nodup_cpp( x ) [1] 2.00 1.00 1.01 2.01 Romain I think this gives a more fair comparison : system.time( nodup_cpp( x ) ) utilisateur système écoulé 0.113 0.002 0.114 system.time( { oo - order(order(x)) ; nodup3( sort( x ) )[oo] } ) utilisateur système écoulé 0.336 0.012 0.347 system.time( { oo - order(order(x)) ; nodup3a( sort( x ) )[oo] } ) utilisateur système écoulé 0.251 0.011 0.262 system.time( { oo - order(order(x)) ; nodup4( sort( x ) )[oo] } ) utilisateur système écoulé 0.287 0.006 0.294 Romain Le 26/11/10 20:01, William Dunlap a écrit : -Original Message- From: William Dunlap Sent: Thursday, November 25, 2010 9:31 AM To: 'randomcz'; r-help@r-project.org Subject: RE: [R] help: program efficiency If the input vector t is known to be ordered (or if you only care about runs of duplicated values, not all duplicated values) the following is pretty quick nodup3- function (t) { t + (sequence(rle(t)$lengths) - 1)/100 } If you don't know if the the input will be ordered then ave() will do it a bit faster than your code nodup2- function (t) { ave(t, t, FUN = function(x) x + (seq_along(x) - 1)/100) } E.g., for a sorted sequence of 300,000 numbers drawn with replacement from 1:100,000 I get: a2- sort(sample(1:1e5, size=3e5, replace=TRUE)) system.time(v- nodup(a2)) user system elapsed 2.78 0.05 3.97 system.time(v2- nodup2(a2)) user system elapsed 1.83 0.02 2.66 system.time(v3- nodup3(a2)) user system elapsed 0.18 0.00 0.14 identical(v,v2) identical(v,v3) [1] TRUE If speed is truly an issue, the built-in sequence may be replaced by a faster one that does the same thing: nodup3a- function (t) { faster.sequence- function(nvec) { seq_len(sum(nvec)) - rep(cumsum(c(0L, nvec[-length(nvec)])), nvec) } t + (faster.sequence(rle(t)$lengths) - 1)/100 } That took 0.05 seconds on the a2 dataset and produced identical results. rle() computes a sort of second difference and nodup3a computes a cumsum on that second diffence, to get back to a first difference. The following avoids that wasted operation (along with rle's computation of the values component of its output). nodup4- function(t) { n- length(t) p- c(0L, which(t[-1L] != t[-n]), n) t + ( seq_len(n) - rep.int(p[-length(p)] + 1L, diff(p)) ) /100 } That reduced nodup3a's time by about 30% on that dataset. Bill Dunlap
Re: [R] Is there an implementation for URL Encoding (/format) in R?
Le 25/11/10 16:53, Tal Galili a écrit : Hello all, I would like some R function that can translate a string to a URL encoding (see here: http://www.w3schools.com/tags/ref_urlencode.asp) Is it implemented? (I wasn't able to find any reference to it) Thanks, Tal Perhaps ?URLencode -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/9VOd3l : ZAT! 2010 |- http://bit.ly/c6DzuX : Impressionnism with R `- http://bit.ly/czHPM7 : Rcpp Google tech talk on youtube __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [Rcpp-devel] fast rowCumsums wanted for calculating the cdf
Hi, This would probably deserve some abstraction, we had C++ versions of apply in our TODO list for some time, but here is a shot: require( Rcpp ) require( inline ) f.Rcpp - cxxfunction( signature( x = matrix ), ' NumericMatrix input( x ) ; NumericMatrix output = cloneNumericMatrix( input ) ; int nr = input.nrow(), nc = input.ncol() ; NumericVector tmp( nr ); for( int i=0; inc; i++){ tmp = tmp + input.column(i) ; NumericMatrix::Column target( output, i ) ; std::copy( tmp.begin(), tmp.end(), target.begin() ) ; } return output ; ', plugin = Rcpp ) f.R - function( x ){ t(apply(probs, 1, cumsum)) #SLOOOW! } probs - t(matrix(rep(1:100),nrow=10)) # matrix with row-wise probabilites stopifnot( all.equal( f.R( probs ), f.Rcpp( probs ) ) ) require( rbenchmark ) probs - t(matrix(rep(1:1000), nrow=10)) # matrix with row-wise probabilites bm - benchmark( f.R( probs ), f.Rcpp( probs ), columns=c(test, elapsed, relative, user.self, sys.self), order=relative, replications=10) print( bm ) I get this on my iMac with R 2.12.0 and Rcpp as just released to CRAN. $ Rscript cumsum.R test elapsed relative user.self sys.self 2 f.Rcpp(probs) 4.614 1.0 4.3750.239 1f.R(probs) 68.645 14.8775567.7650.877 When we implement apply in C++, we will probably leverage loop unrolling to achieve greater performance. Romain Le 15/10/10 14:34, Douglas Bates a écrit : Although I know there is another message in this thread I am replying to this message to be able to include the whole discussion to this point. Gregor mentioned the possibility of extending the compiled code for cumsum so that it would handle the matrix case. The work by Dirk Eddelbuettel and Romain Francois on developing the Rcpp package make it surprisingly easy to create compiled code for this task. I am copying the Rcpp-devel list on this in case one of the readers of that list has time to create a sample implementation before I can get to it. It's midterm season and I have to tackle the stack of blue books on my desk before doing fun things like writing code. On Fri, Oct 15, 2010 at 2:23 AM, Joshua Wileyjwiley.ps...@gmail.com wrote: Hi, You might look at Reduce(). It seems faster. I converted the matrix to a list in an incredibly sloppy way (which you should not emulate) because I cannot think of the simple way. probs- t(matrix(rep(1:1000), nrow=10)) # matrix with row-wise probabilites F- matrix(0, nrow=nrow(probs), ncol=ncol(probs)); F[,1]- probs[,1,drop=TRUE]; add- function(x) {Reduce(`+`, x, accumulate = TRUE)} system.time(F.slow- t(apply(probs, 1, cumsum))) user system elapsed 36.758 0.416 42.464 system.time(for (cc in 2:ncol(F)) { + F[,cc]- F[,cc-1,drop=TRUE] + probs[,cc,drop=TRUE]; + }) user system elapsed 0.980 0.196 1.328 system.time(add(list(probs[,1], probs[,2], probs[,3], probs[,4], probs[,5], probs[,6], probs[,7], probs[,8], probs[,9], probs[,10]))) user system elapsed 0.420 0.072 0.539 .539 seconds for 10 vectors each with 1 million elements does not seem bad. For 3 each, on my system it took .014 seconds, which for 200,000 iterations, I estimated as: (20*.014)/60/60 [1] 0.778 (and this is on a stone age system with a single core processor and only 756MB of RAM) It should not be difficult to get the list back to a matrix. Cheers, Josh On Thu, Oct 14, 2010 at 11:51 PM, Gregormailingl...@gmx.at wrote: Dear all, Maybe the easiest solution: Is there anything that speaks against generalizing cumsum from base to cope with matrices (as is done in matlab)? E.g.: cumsum(Matrix, 1) equivalent to apply(Matrix, 1, cumsum) The main advantage could be optimized code if the Matrix is extreme nonsquare (e.g. 100,000x10), but the summation is done over the short side (in this case 10). apply would practically yield a loop over 100,000 elements, and vectorization w.r.t. the long side (loop over 10 elements) provides considerable efficiency gains. Many regards, Gregor On Tue, 12 Oct 2010 10:24:53 +0200 Gregormailingl...@gmx.at wrote: Dear all, I am struggling with a (currently) cost-intensive problem: calculating the (non-normalized) cumulative distribution function, given the (non-normalized) probabilities. something like: probs- t(matrix(rep(1:100),nrow=10)) # matrix with row-wise probabilites F- t(apply(probs, 1, cumsum)) #SLOOOW! One (already faster, but for sure not ideal) solution - thanks to Henrik Bengtsson: F- matrix(0, nrow=nrow(probs), ncol=ncol(probs)); F[,1]- probs[,1,drop=TRUE]; for (cc in 2:ncol(F)) { F[,cc]- F[,cc-1,drop=TRUE] + probs[,cc,drop=TRUE]; } In my case, probs is a (30,000 x 10) matrix, and i need to iterate this step around 200,000 times, so speed is crucial. I currently can make sure to have no NAs, but in order to extend matrixStats, this could be a nontrivial issue. Any ideas for speeding up
Re: [R] RJava help
Le 14/10/10 20:28, lord12 a écrit : I need help with RJava. So I run this R code: library(rJava) #load the rJava library .jinit(classpath=c:/Documents and Settings/GV/workspace/Test/src, parameters=-Xmx512m) #the above is to load the Java virtual machine, x = runif(1000) y = runif(1000) #the above are two vectors to convolve #now you can call the Java method as z=.jcall(Test, [D, convolve, x,y) I get an error Error in .jcall(Test, [D, convolve, x, y) : RcallMethod: cannot determine object class. Why is this? It would be useful if you showed your Test java class and repost on the appropriate mailing list for rJava: http://mailman.rz.uni-augsburg.de/mailman/listinfo/stats-rosuda-devel Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/b8wOqW : LondonR Rcpp slides |- http://bit.ly/cCmbgg : Rcpp 0.8.6 `- http://bit.ly/bzoWrs : Rcpp svn revision 2000 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to convert SEXP to double
Le 28/09/10 08:43, Dmitrij Kudriavcev a écrit : Hello All, A simple question. I get some return from the R in my C++ program (via Rcpp package). The result come, as SEXP and it should be a simple numeric variable. How to convert it to double? The code, what i use: stringstream ss; ss p- predict(fit_ar11, n.ahead = 2, doplot=FALSE); p$pred[1]; SEXP ans; int iRet = R.parseEval(ss.str().c_str()); if (iRet == 0 ans != NULL) { // ??? } Cheers, Dima Hello, Questions about Rcpp should go to the Rcpp-devel mailing list (cc'ed). You probably meant to use thsi version of parseEval: int parseEval(const std::string line, SEXP ans); // parse line, return in ans; error code rc In your example ans is never used or initialized, so you have less than zero chances of it to work. With recent versions of RInside, you may just do : double res = R.parseEval( ss.str().c_str() ) ; conversion will work itself out. why: parseEval implements the proxy pattern: RInside::Proxy RInside::parseEval(const std::string line) { SEXP ans; int rc = parseEval(line, ans); if (rc != 0) { throw std::runtime_error(std::string(Error evaluating: ) + line); } return Proxy( ans ); } and Proxy has a templated implicit conversion operator: class Proxy { public: Proxy(SEXP xx): x(xx) { }; template typename T operator T() { return ::Rcpp::asT(x); } private: Rcpp::RObject x; }; Please register to the Rcpp-devel mailing list of you have follow up questions. Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/cCmbgg : Rcpp 0.8.6 |- http://bit.ly/bzoWrs : Rcpp svn revision 2000 `- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] get absolute file path
Le 26/09/10 10:00, Sebastian Gibb a écrit : Hello, I get a value which stores a relative file name. (I get it from another function, which I don't want to change.) e.g. fileName- ../data/2010-08.csv; Is it possible to get the absolute file path out of this value? (e.g. /home/sebastian/documents/data/2010-08.csv) Kind regards, Sebastian Hi, I often use tools:::file_path_as_absolute which is not exported from the tools namespace, but does the job. Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/cCmbgg : Rcpp 0.8.6 |- http://bit.ly/bzoWrs : Rcpp svn revision 2000 `- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] get absolute file path
Le 26/09/10 12:18, Kurt Hornik a écrit : Sebastian Gibb writes: Am Sonntag, 26. September 2010, 10:08:39 schrieb Romain Francois: Le 26/09/10 10:00, Sebastian Gibb a écrit : Hello, I get a value which stores a relative file name. (I get it from another function, which I don't want to change.) e.g. fileName- ../data/2010-08.csv; Is it possible to get the absolute file path out of this value? (e.g. /home/sebastian/documents/data/2010-08.csv) Kind regards, Sebastian Hi, I often use tools:::file_path_as_absolute which is not exported from the tools namespace, but does the job. Romain Hello Romain, thank you, this function works like expected. Why is it hidden? Afaics it is exported and documented. oops. -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/cCmbgg : Rcpp 0.8.6 |- http://bit.ly/bzoWrs : Rcpp svn revision 2000 `- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] characters in a string
Le 15/09/10 17:16, raje...@cse.iitm.ac.in a écrit : Hi, I need to check if a string rha,b,c,drh is delimited by tworh 's as efficiently as possible(I need to do this a lot of times) and return TRUE. Can someone suggest a good technique? Hi Rajesh, f - function( x ) grepl( ^rh.*rh$, x ) f( rha,b,c,drh ) [1] TRUE See ?grepl for details. Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/cCmbgg : Rcpp 0.8.6 |- http://bit.ly/bzoWrs : Rcpp svn revision 2000 `- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] faster unlist,strsplit,gsub,for
Hi, You can leverage read.table using a textConnection: txt - x,y,z,a,b,c,dda,b,c,d,e,f,gd con - textConnection( gsub( d, \\\n, txt ) ) read.table( con, sep = , ) V1 V2 V3 V4 V5 V6 V7 1 x y z a b c d 2 a b c d e f g close( con ) Romain Le 10/09/10 06:41, rajesh j a écrit : Ok. These operations are on a string and the result is added to a data.frame. I have strings of the form x,y,z,a,b,c,dda,b,c,d,e,f,gd essentially comma separated values delimited by ad I first do a unlist(strsplit(string,split=d)) and then a strsplit(string,split=,) The list of vectors i end up with is added row by row to a preallocated data.frame like.. df[i,]-list[[i]] all of this is in a for loop and it runs for 1000 times atleast and the strings are 7000 to 8000 characters in length On Fri, Sep 10, 2010 at 9:14 AM, jim holtmanjholt...@gmail.com wrote: First thing to do is to use Rprof to profile your code to see where the time is being spent, then you can make a decision as to what to change. Are you carrying out the operations on a dataframe, if so can you change it to a matrix for some of the operations? You have provided no idea of what your code or data looks like, or how often each of the operations is being done. There are probably many ways of speeding up the code, but with no idea of what the code is, no solutions can be specified. On Thu, Sep 9, 2010 at 11:09 PM, rajesh jakshay.raj...@gmail.com wrote: Hi, I perform the operations unlist,strsplit,gsub and the for loop on a lot of strings and its heavily slowing down the overall system. Is there some way for me to speeden up these operations..maybe like alternate versions that exist which use multiprocessors etc. -- Rajesh.J -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/bzoWrs : Rcpp svn revision 2000 |- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th `- http://bit.ly/aAyra4 : highlight 0.2-2 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Rserve (Anyone?)
Questions about Rserve typically go to this mailing list: http://mailman.rz.uni-augsburg.de/mailman/listinfo/stats-rosuda-devel Le 20/08/10 06:25, Donald Paul Winston a écrit : REXP has an asBytes() method. Will this capture the output of an R plot function if a proper graphics device is used? It appears R insists on sending plot output to a file. Kind of strange since it insists on loading all your data into memory before it can do anything. If so then does anyone know what this would be? I prefer png or jpeg. Example: c is an RConnection REXP r = c.eval(png(..); plot(1:25, cex=2, pch=c(1:25))); Then I can write the r.asBytes() to an output stream. (I think I already know the answer to this, just hoping I'm wrong) r will be NULL. Before you do it over Rserve, try to do it in R : x - plot(1:25, cex=2, pch=c(1:25)) x NULL What you can do is close the device (calling dev.off()), and then send the file accross the wire. Rserve has some methods for file transfer. For example, see : http://romainfrancois.blog.free.fr/index.php?post/2009/08/04/Transfer-files-through-Rserve Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/bzoWrs : Rcpp svn revision 2000 |- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th `- http://bit.ly/aAyra4 : highlight 0.2-2 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R and Java
Le 20/08/10 17:56, Allan Freitas a écrit : Hi folks, Maybe that is not the best place to ask, No it is not, this is: http://mailman.rz.uni-augsburg.de/mailman/listinfo/stats-rosuda-devel but I 'd like some of you could help me... I'm using jri to run R commands under Java, by its examples I can eval expressions, returning single values or vectors to my Java variables. But, I would like to know how to assign the values of a Java vector (like: double x[] = {1.7 , 2.8 , 3.4}; ) to a R variable, so I can eval a function using it (like: mean(x) ). Someone could help me? Best regards, Perhaps you can give some more meat to your question, write some code with what you tried, why it failed, etc ... and repost on the appropriate mailing list (see above). hint: http://rforge.net/Rserve/doc/org/rosuda/REngine/REngine.html#assign%28java.lang.String,%20double[]%29 Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/bzoWrs : Rcpp svn revision 2000 |- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th `- http://bit.ly/aAyra4 : highlight 0.2-2 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Random Number Generators and Sample
Le 16/08/10 09:35, Linda Eaton a écrit : I am trying to get documentation about the random number generator used in sample. The help for sample does not mention it. Can anyone point me in the right direction. Thanks Hi, You can follow the white rabbit into the code burrow. sample function (x, size, replace = FALSE, prob = NULL) { if (length(x) == 1L is.numeric(x) x = 1) { if (missing(size)) size - x .Internal(sample(x, size, replace, prob)) } else { if (missing(size)) size - length(x) x[.Internal(sample(length(x), size, replace, prob))] } } environment: namespace:base so you need to look for the internal sample, you can search for this in the file src/main/names.c in the R source, you'll see that line : {sample,do_sample, 0, 11, 4, {PP_FUNCALL, PREC_FN, 0}}, Then you grep for do_sample in the src/main directory, which leads you to the random.c file : /* do_sample - probability sampling with/without replacement. .Internal(sample(n, size, replace, prob)) */ SEXP attribute_hidden do_sample(SEXP call, SEXP op, SEXP args, SEXP rho) You'll have all the details there. Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/bzoWrs : Rcpp svn revision 2000 |- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th `- http://bit.ly/aAyra4 : highlight 0.2-2 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] incrementing matrix elements more efficiently
Le 15/08/10 02:43, david h shanabrook a écrit : I need to increment cells of a matrix (collusionM). The indexes to increment are in an index (matchIndex). This is sample code library(seqinr) library(Matrix) x- abcabcabc mx- s2c(x) collisionM- Matrix(0,nrow=10, ncol=10, sparse=TRUE) matchIndex- list() rows- length(mx) for (j in 1:(rows)) matchIndex[[j]]- which(mx[j]==mx) for (j in 1:(rows)) collisionM[j,matchIndex[[j]]]- collisionM[j,matchIndex[[j]]] + 1 Works fine, except with my data (rows=32000) it is too slow. The problem is the second for loop, where it increments the index of the sparse matrix; this needs to be rewritten so it is more efficient. Any ideas? Hi, Nice exercise to demonstrate matrix indexing. First let's look at it on a simpler example: x - matrix( 1:16, nr = 4 ) x [,1] [,2] [,3] [,4] [1,]159 13 [2,]26 10 14 [3,]37 11 15 [4,]48 12 16 y - cbind( c(1,2,3,4), c(1,2,3,4) ) y [,1] [,2] [1,]11 [2,]22 [3,]33 [4,]44 x[ y ] [1] 1 6 11 16 Now we can apply it to your example, below f is your code and g uses matrix indexing: f - function(x = abcabcabc){ mx - s2c(x) rows - length(mx) collisionM - Matrix(0,nrow=rows, ncol=rows, sparse=TRUE) matchIndex - list() for (j in 1:(rows)) matchIndex[[j]] - which(mx[j]==mx) for (j in 1:(rows)) collisionM[j,matchIndex[[j]]] - collisionM[j,matchIndex[[j]]] + 1 collisionM } g - function( x = abcabcabc){ mx - s2c(x) rows - length(mx) collisionM - Matrix(0,nrow=rows, ncol=rows, sparse=TRUE) matchIndex - do.call( rbind, lapply( 1:rows, function( i){ cbind( i, which( mx[i] == mx ) ) } ) ) collisionM[ matchIndex ] - collisionM[matchIndex] + 1 collisionM } # first check it works as expected : all( f() == g() ) [1] TRUE # then do some timings long - paste( sample(letters, 1000, replace = TRUE ), collapse = ) system.time( f( x = long ) ) user system elapsed 8.022 1.052 9.074 system.time( g( x = long ) ) user system elapsed 0.079 0.003 0.082 ... and it seems we don't even need indexing at all, we can just create the matrix using sparseMatrix : h - function( x = abcabcabc){ mx - s2c(x) rows - length(mx) matchIndex - do.call( rbind, lapply( 1:rows, function( i){ cbind( i, which( mx[i] == mx ) ) } ) ) sparseMatrix( matchIndex[,1], matchIndex[,2] ) } which gives some improvement : system.time( h( x = long ) ) user system elapsed 0.048 0.000 0.048 Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/bzoWrs : Rcpp svn revision 2000 |- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th `- http://bit.ly/aAyra4 : highlight 0.2-2 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating list from a long vector
Le 14/08/10 18:22, steven mosher a écrit : Stupid question, but its been a long night. If I have a long vector how can I turn it into a list of the same length x-rep(seq(1,100,by=1),each=10) Perhaps as.list ? -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/bzoWrs : Rcpp svn revision 2000 |- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th `- http://bit.ly/aAyra4 : highlight 0.2-2 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] cacheSweave / pgfSweave driver for package vignette
Le 14/08/10 19:13, baptiste auguie a écrit : Thank you everyone, I think I'll follow the technique used in Rcpp (dummy vignettes + Makefile). Cool. Let us (Rcpp team) know if you find better ways or if something is too much trickery. It would be great to have a mechanism to select the driver for vignette generation though. Also, as a side-note, the choice of a driver has its own shortcoming; I cannot use the features of highlight and, say, pgfSweave in the same document. It should be possible to create a new driver that combines both features. Let me (highlight team) know if I can do something in highlight to make this easier than it currently is. Romain Sincerely, baptiste On 13 August 2010 11:10, Romain Francoisromain.franc...@dbmail.com wrote: Hi, I've been meaning to ask the same question before. Le 13/08/10 11:01, baptiste auguie a écrit : Dear list, I wish to use a specific driver to process an sweave document in the inst/doc directory of a package. Specifically, I would like to use either cacheSweave or pgfSweave to speed up the creation of the vignette which requires lengthy computations. The same request would also apply to the highlight driver, to provide syntax highlighting of R chunks. In writing R extensions I see that during R CMD BUILD Sweave is run first, then optionally a makefile can be used to process any other files. It doesn't seem to leave room for a choice of Sweave engine, as far as I understand. One option I am thinking of is to change the extension of the source file to something like .Rnw2 so that Sweave ignores it altogether, and then use the appropriate command in a makefile. This is what we do in Rcpp to build our 7 vignettes (since we like to use the driver from highlight). One thing to have in mind is that R needs the .Rnw file to be present in doc once the package is installed, so that the vignette function works, hence some trickery in Rcpp. A way to control which sweave (and perhaps tangle) driver is to be used for a particular vignette would be very useful. Romain I have no experience in writing makefiles, so I'm hoping someone would already have solved this issue and could provide some advice. Sincerely, baptiste -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/bzoWrs : Rcpp svn revision 2000 |- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th `- http://bit.ly/aAyra4 : highlight 0.2-2 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] cacheSweave / pgfSweave driver for package vignette
Hi, I've been meaning to ask the same question before. Le 13/08/10 11:01, baptiste auguie a écrit : Dear list, I wish to use a specific driver to process an sweave document in the inst/doc directory of a package. Specifically, I would like to use either cacheSweave or pgfSweave to speed up the creation of the vignette which requires lengthy computations. The same request would also apply to the highlight driver, to provide syntax highlighting of R chunks. In writing R extensions I see that during R CMD BUILD Sweave is run first, then optionally a makefile can be used to process any other files. It doesn't seem to leave room for a choice of Sweave engine, as far as I understand. One option I am thinking of is to change the extension of the source file to something like .Rnw2 so that Sweave ignores it altogether, and then use the appropriate command in a makefile. This is what we do in Rcpp to build our 7 vignettes (since we like to use the driver from highlight). One thing to have in mind is that R needs the .Rnw file to be present in doc once the package is installed, so that the vignette function works, hence some trickery in Rcpp. A way to control which sweave (and perhaps tangle) driver is to be used for a particular vignette would be very useful. Romain I have no experience in writing makefiles, so I'm hoping someone would already have solved this issue and could provide some advice. Sincerely, baptiste -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th |- http://bit.ly/aAyra4 : highlight 0.2-2 `- http://bit.ly/94EBKx : inline 0.3.6 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to extract the conf.level out of t.test() data
Le 09/08/10 20:39, Etienne Stockhausen a écrit : Good afternoon everybody, I'm writing a little function to visualise hypothesis testing. Therefore I need to extract the confidence level of a t-test. Here a little example: x - str(t.test(1:10) gives List of 9 $ statistic : Named num 5.74 ..- attr(*, names)= chr t $ parameter : Named num 9 ..- attr(*, names)= chr df $ p.value : num 0.000278 $ conf.int : atomic [1:2] 3.33 7.67 ..- attr(*, conf.level)= num 0.95 $ estimate : Named num 5.5 ..- attr(*, names)= chr mean of x $ null.value : Named num 0 ..- attr(*, names)= chr mean $ alternative: chr two.sided $ method : chr One Sample t-test $ data.name : chr 1:10 - attr(*, class)= chr htest Now I can use x$conf.int what gives [1] 496.9141 499.6276 attr(,conf.level) [1] 0.95 In the example I try to extract the value 0.95 but I have no Idea how. I hope somebody can help me. Thanks in advance an greetings from Berlin Etienne You need the conf.level attribute, as in : x - t.test(1:10) attr( x$conf.int, conf.level ) Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/aAyra4 : highlight 0.2-2 |- http://bit.ly/94EBKx : inline 0.3.6 `- http://bit.ly/aryfrk : useR! 2010 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Identifying integers (as opposed to real #s) in matrix
Le 10/08/10 10:05, David Katz a écrit : Is there a way to identify (for subsequent replacement) which rows in a matrix are comprised entirely of *integers*? I have a large set of *nx3 *matrices where each row either consists of a set of 3 integers or a set of 3 real numbers. A given matrix might looks something like this: [ ,1] [ ,2] [ ,3] [1, ] 121.-98. 276. [2, ] 10.1234 25.4573 -188.9204 [3, ] 121.-98. 276. [4, ] -214.4982 -99.1043-312.0495 . [n, ] 99. 1. -222. Ultimately, I'm going to replace the values in the integer-only rows with NAs. But first I need r to recognize the integer-only rows. I assume whatever function I write will be keyed off of the .s, but have no clue how to write that function. Any ideas? David Katz Something like this perhaps: x - rbind( c(1, 2, 3), c(1.2,2.2, 3.2), c(1,2,3), c(1.2, 1.2, 1.3 ) ) x [,1] [,2] [,3] [1,] 1.0 2.0 3.0 [2,] 1.2 2.2 3.2 [3,] 1.0 2.0 3.0 [4,] 1.2 1.2 1.3 rowSums( x == round(x) ) == ncol(x) [1] TRUE FALSE TRUE FALSE x[ rowSums( x == round(x) ) == ncol(x) , ] - NA x [,1] [,2] [,3] [1,] NA NA NA [2,] 1.2 2.2 3.2 [3,] NA NA NA [4,] 1.2 1.2 1.3 Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/aAyra4 : highlight 0.2-2 |- http://bit.ly/94EBKx : inline 0.3.6 `- http://bit.ly/aryfrk : useR! 2010 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sciviews-K -- object 'httpdPort' not found
Hi, httpdPort arrived with R 2.10.0, apparently Sciviews-K relies on this, so you need to upgrade R to a newer version. Romain Le 05/08/10 19:16, Albert-Jan Roskam a écrit : Hi, I'm trying to install Sciviews-K on Linux Ubuntu 9.10 (karmic) but I'm not able to establish the connection between Komodo and R. Here;s the error I get, plus some diagnostic info: R version 2.9.2 (2009-08-24) R is SciViews ready! Error in get(name, envir = asNamespace(pkg), inherits = FALSE) : object 'httpdPort' not found ls() [1] svStart Sys.info() sysname Linux release 2.6.31-22-generic version #60-Ubuntu SMP Thu May 27 00:22:23 UTC 2010 getBuiltinRhome.GString() [1] /usr/lib/R Does anybody know how to resolve this? Thanks in advance! Cheers!! Albert-Jan -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/aAyra4 : highlight 0.2-2 |- http://bit.ly/94EBKx : inline 0.3.6 `- http://bit.ly/aryfrk : useR! 2010 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How get colnames and rownames in Rcpp method?
Hi, This is not the appropriate list for questions about Rcpp. See the Rcpp-devel mailing list, but first please think about a reproducible example. Romain Le 28/07/10 14:11, 나여나 a écrit : Hi all, How get colnames and rownames in Rcpp method? attecthed file : RGui.exe capture my work environment : R version : 2.11.1 OS : WinXP Pro sp3 Thanks and best regards. Young-Ju, Park from Korea [1][rKWLzcpt.zNp8gmPEwGJCA00] [...@from=dllmainrcpt=r%2Dhelp%40r%2Dproject%2Eorgmsgid=%3C20100728211143%2EH M%2E0c7%40dllmain%2Ewwl737%2Ehanmail%2Enet%3E] References 1. mailto:dllm...@hanmail.net -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/aryfrk : useR! 2010 |- http://bit.ly/bc8jNi : Rcpp 0.8.4 `- http://bit.ly/dz0RlX : bibtex 0.2-1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problem with building package on CRAN
Hello, (ccing Rcpp-devel too because this is relevant) This comes up every now and again on packages that are completely unrelated to Rcpp. We don't know yet why or what to do to fix the issue. I believe (but this might not be the case) that this is due to packages that do use Rcpp and fail to follow our guidelines and documentation and emails about using LinkingTo to pull in header files. See http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2010-July/000898.html I'm really sorry you are caught in the middle of this, there is probably nothing wrong with your package, it just happens sort of randomly. I believe the chances of this happening would be lower if package developers (of package using Rcpp) would be so kind and follow our guidelines, but we can only offer to write the guidelines, we cannot force them to read or apply them. Romain Le 26/07/10 22:43, William Revelle a écrit : Dear friends, I have just gotten a strange error message back from Uwe saying that the most recent version of psych failed to pass R CMD check for Windows. The error message was less than helpful, in that it seems to have failed when trying to include the Rcpp library, which I do not directly call. (see below) * using log directory 'd:/Rcompile/CRANpkg/local/2.11/psych.Rcheck' * using R version 2.11.1 (2010-05-31) * using session charset: ISO8859-1 * checking for file 'psych/DESCRIPTION' ... OK * this is package 'psych' version '1.0-90' * checking package name space information ... OK * checking package dependencies ... OK * checking if this is a source package ... OK * checking whether package 'psych' can be installed ... ERROR Installation failed. The installation logfile: -Id:/Rcompile/CRANpkg/lib/2.11/Rcpp/include I do have several suggested packages (polycor, GPArotation, MASS, graph, Rgraphviz, mvtnorm, Rcsdp), but none of these are actually required. My examples all ask if the suggested packages are available and then do not call them if they are not. Any suggestions on what to do would be appreciated. Thanks. Bill -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/bc8jNi : Rcpp 0.8.4 |- http://bit.ly/dz0RlX : bibtex 0.2-1 `- http://bit.ly/a5CK2h : Les estivales 2010 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] O/T good c/c++ code for LU decomposition
Hi, Armadillo (http://arma.sourceforge.net/docs.html) has LU. Here is an example adapted from armadillo's documentation using Rcpp/RcppArmadillo and inline: require( inline ) require( RcppArmadillo ) fx - cxxfunction( signature( A_ = matrix), ' using namespace arma ; mat A = asmat(A_); mat L; mat U; mat P; lu(L, U, P, A); mat B = trans(P)*L*U; return List::create( _[L] = L, _[U] = U, _[P] = P, _[A] = A, _[B] = B ) ; ', plugin = RcppArmadillo ) fx( matrix( runif(100), 10, 10) ) Romain Le 26/07/10 23:46, Erin Hodgess a écrit : Dear R People: Could someone recommend a good c/c++ code (or Fortran) for LU decomposition, please? Sorry to bother about this. I'm trying to do some non-R work that requires a matrix inversion. Thanks, Erin -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/bc8jNi : Rcpp 0.8.4 |- http://bit.ly/dz0RlX : bibtex 0.2-1 `- http://bit.ly/a5CK2h : Les estivales 2010 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to generate PDF help file for our internal R package?
Le 17/07/10 08:23, noclue_ a écrit : Currently, we have developed an R package for our company's internal use (at least for now). I have successfully built the package and generated zip file which can be easily installed. However, I am not sure how to generate the big HELP file in PDF. Right now, I have about 30+ Rd files for this internal package. I can run 'R CMD Rd2dvi' and WinEdt to create one pdf file individually for each Rd file. But I have not been successful in getting one big pdf file. Does anybody know how to generate a complete pdf file for the package ? Thanks! From the directory that contains your package : $ R CMD Rd2dvi yourpackage Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/bc8jNi : Rcpp 0.8.4 |- http://bit.ly/dz0RlX : bibtex 0.2-1 `- http://bit.ly/a5CK2h : Les estivales 2010 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fast string comparison
Hi Matt, I think there are some confusing factors in your results. system.time(strcmp(strings[-1], strings[-1e5])) would also include the time required to perform both subscripting (strings[-1] and strings[-1e5] ) which actually takes some time. Also, you do have a bit of overhead due to the use of STRING_ELT and the write barrier. I've include below a version that uses R internals so that you get the fast (but you have to understand the risks, etc ...) version of STRING_ELT using the plugin system of inline. library(inline) code - SEXP ans; int i, len, *cans; if(!isString(s1) || !isString(s2)) error(\invalid arguments\); len = length(s1)length(s2)?length(s2):length(s1); PROTECT(ans = allocVector(INTSXP, len)); cans = INTEGER(ans); for(i = 0; i len; i++) cans[i] = strcmp(CHAR(STRING_ELT(s1,i)),\ CHAR(STRING_ELT(s2,i))); UNPROTECT(1); return ans; sig - signature(s1=character, s2=character) strcmp - cfunction(sig, code) strings - replicate(1e5, paste(sample(letters, 100, rep = T), collapse = )) lhs - strings[-1] rhs - strings[-1e5] system.time( lhs == rhs ) system.time(strcmp( lhs, rhs) ) library(inline) settings - getPlugin( default ) settings$includes - paste( #define USE_RINTERNALS, settings$includes, collapse = \n ) code2 - SEXP ans; int i, len, *cans; if(!isString(s1) || !isString(s2)) error(\invalid arguments\); len = length(s1)length(s2)?length(s2):length(s1); PROTECT(ans = allocVector(INTSXP, len)); cans = INTEGER(ans); for(i = 0; i len; i++) cans[i] = strcmp(CHAR(STRING_ELT(s1,i)),\ CHAR(STRING_ELT(s2,i))); UNPROTECT(1); return ans; sig - signature(s1=character, s2=character ) strcmp2 - cxxfunction(sig, code2, settings = settings) system.time(strcmp2( lhs, rhs) ) I get: $ Rscript strings.R Le chargement a nécessité le package : methods utilisateur système écoulé 0.002 0.000 0.002 utilisateur système écoulé 0.004 0.000 0.005 utilisateur système écoulé 0.003 0.000 0.003 Romain Le 13/07/10 15:24, Matt Shotwell a écrit : On Tue, 2010-07-13 at 01:42 -0400, Hadley Wickham wrote: strings- replicate(1e5, paste(sample(letters, 100, rep = T), collapse = )) system.time(strings[-1] == strings[-1e5]) # user system elapsed # 0.016 0.000 0.017 So it takes ~1/100 of a second to do ~100,000 string comparisons. You need to provide a reproducible example that illustrates why you think string comparisons are slow. Here's a vectorized alternative to '==' for strings, with minimal argument checking or result conversion. I haven't looked at the corresponding R source code, it may be similar: library(inline) code- SEXP ans; int i, len, *cans; if(!isString(s1) || !isString(s2)) error(\invalid arguments\); len = length(s1)length(s2)?length(s2):length(s1); PROTECT(ans = allocVector(INTSXP, len)); cans = INTEGER(ans); for(i = 0; i len; i++) cans[i] = strcmp(CHAR(STRING_ELT(s1,i)),\ CHAR(STRING_ELT(s2,i))); UNPROTECT(1); return ans; sig- signature(s1=character, s2=character) strcmp- cfunction(sig, code) system.time(strings[-1] == strings[-1e5]) user system elapsed 0.036 0.000 0.035 system.time(strcmp(strings[-1], strings[-1e5])) user system elapsed 0.032 0.000 0.034 That's pretty fast, though I seem to be working with a slower system than Hadley. It's hard to see how this could be improved, except maybe by caching results of string comparisons. -Matt Hadley On Tue, Jul 13, 2010 at 6:52 AM, Ralf Bralf.bie...@gmail.com wrote: I am asking this question because String comparison in R seems to be awfully slow (based on profiling results) and I wonder if perhaps '==' alone is not the best one can do. I did not ask for anything particular and I don't think I need to provide a self-contained source example for the question. So, to re-phrase my question, are there more (runtime) effective ways to find out if two strings (about 100-150 characters long) are equal? Ralf On Sun, Jul 11, 2010 at 2:37 PM, Sharpiech...@sharpsteen.net wrote: Ralf B wrote: What is the fastest way to compare two strings in R? Ralf Which way is not fast enough? In other words, are you asking this question because profiling showed one of R's string comparison operations is causing a massive bottleneck in your code? If so, which one and how are you using it? -Charlie -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/bc8jNi : Rcpp 0.8.4 |- http://bit.ly/dz0RlX : bibtex 0.2-1 `- http://bit.ly/a5CK2h : Les estivales 2010 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read
Re: [R] nested for loops
Le 05/07/10 23:06, Senay ASMA a écrit : Dear Admin, I will appreciate if you advise me an effective way to write the following R code including nested for loops. I cannot do it by using expand.grid function because it results with memory allocation problems. Thanks for your time and consideration. for(d1 in 0:n){ for(d2 in 0:n){ for(d3 in 0:n){ for(d4 in 0:n){ for(d5 in 0:n){ for(d6 in 0:n){ for(d7 in 0:n){ for(d8 in 0:n){ for(d9 in 0:n){ for(d10 in 0:n){ for(d11 in 0:n){ for(d12 in 0:n){ for(d13 in 0:n){ for(d14 in 0:n){ for(d15 in 0:n){ for(d16 in 0:n){ for(d17 in 0:n){ for(d18 in 0:n){ for(d19 in 0:n){ for(d20 in 0:n){ list=c(d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15,d16,d17,d18,d19,d20) Probably not what you want, but this should replicate the same effect as the code you posted: list - rep( n, 20 ) Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/98Uf7u : Rcpp 0.8.1 |- http://bit.ly/c6YnCi : graph gallery collage `- http://bit.ly/bZ7ltC : inline 0.3.5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Call by reference or suggest workaround
Le 19/06/10 16:32, Chidambaram Annamalai a écrit : I have written code to compute multi-indices in R [1] and due to the recursive nature of the computation I need to pass around the *same* matrix object (where each row corresponds to one multi-index). As pass by reference wasn't the default behavior I declared a global matrix (mat) and used the- operator to write to the global matrix. So the usage would be to call genMultiIndices(3,2) for side effects to generate all multi-indices of length 3 and sum 2. And then access the global matrix. However, after coding this I can't seem to export the global matrix object (in the NAMESPACE file) and still retain mutability since its binding is locked (R throws an error). Can I somehow unlock this? Ideally I would want to pass around the same matrix to the recursive function. Is that possible? If not, could someone please suggest a workaround to use the code in an R package? [1]: http://dpaste.com/209186/ Hi, You can use lexical scoping and you might like ?Recall as well. genMultiIndices - function(N, V) { mat - matrix(nrow=choose(N + V - 1, V), ncol=N) fillMultiIndices - function(i, j, n, v) { if (n == 1) { mat[i, j] - v } else if (v == 0) { mat[i, j:(j + n - 1)] - 0L } else { rowOffset - 0 # the first element of each multi-index can be any of 0, 1, ..., v for (k in v:0) { times - choose((n - 1) + (v - k) - 1, (v - k)) mat[(i + rowOffset):(i + rowOffset + times - 1), j] - k Recall(i + rowOffset, j + 1, n - 1, v - k) rowOffset - rowOffset + times } } } fillMultiIndices(1, 1, N, V) mat } Also, you can consider writing your code in a language that supports references, e.g. C++. Here is a start with inline/Rcpp : require( inline ) require( Rcpp ) genMultiIndices_internal - local({ inc - ' void fillMultiIndices( Rcpp::IntegerMatrix mat, int i, int j, int n, int v ){ if( n == 1 ){ mat( (i-1), (j-1) ) = v ; } else if( v == 0 ){ for( int k=j; k j+n; k++){ mat( (i-1), (k-1) ) = 0 ; } } else { // using the R function // I leave it to you to use a C implementation Function choose( choose ) ; int rowOffset = 0 ; int times ; for( int k=v; k=0; k--){ times = asint( choose( (n-1) + (v-k) - 1, (v-k) ) ); int start = i + rowOffset ; int end = i + rowOffset + times ; for( int z = start; z end; z++ ){ mat( z-1 , j-1 ) = k ; } fillMultiIndices( mat, i + rowOffset, j+1, n-1, v-k ) ; rowOffset += times ; } } } ' code - ' int N = asint( N_) ; int V = asint( V_) ; int NR = asint( NR_) ; Rcpp::IntegerMatrix mat( NR, N ) ; fillMultiIndices( mat, 1, 1, N, V ) ; return mat ; ' .genMultiIndices - cxxfunction( signature( N_ = integer, V_ = integer, NR_ = integer ), code, include = inc, plugin = Rcpp ) function( N, V){ .genMultiIndices( N, V, choose(N + V - 1, V) ) } } ) I've been lazy here and I am using the choose function from R, so there is room for some improvement. ( x - genMultiIndices( 3L , 2L ) ) [,1] [,2] [,3] [1,]200 [2,]110 [3,]101 [4,]020 [5,]011 [6,]002 ( y - genMultiIndices_internal( 3L, 2L ) ) [,1] [,2] [,3] [1,]200 [2,]110 [3,]101 [4,]020 [5,]011 [6,]002 identical( x, y ) [1] TRUE Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/98Uf7u : Rcpp 0.8.1 |- http://bit.ly/c6YnCi : graph gallery collage `- http://bit.ly/bZ7ltC : inline 0.3.5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] C interface
Hello, This is not the appropriate mailing list. Use R-devel for questions about C, etc ... One thing that might help you is the inline package. require( inline ) fx - cfunction( signature( s = numeric ), ' SEXP result; PROTECT(result = NEW_NUMERIC(1)); double* ptr=NUMERIC_POINTER(result); double t = *REAL(s); double u = t-floor(t)-0.5; if(u0) *ptr=-1+4*u; else *ptr=-1-4*u; Rprintf(The value is %f, *ptr); UNPROTECT(1); return result; ', verbose = TRUE ) fx( 10 ) The verbose = TRUE argument will show you how inline runs the show. Romain Le 18/06/10 16:18, michael meyer a écrit : Greetings, I am trying to call simple C-code from R. I am on Windows XP with RTools installed. The C-function is #includeR.h #includeRinternals.h #includeRmath.h #includeRdefines.h // prevent name mangling extern C { SEXP __cdecl test(SEXP s){ SEXP result; PROTECT(result = NEW_NUMERIC(1)); double* ptr=NUMERIC_POINTER(result); double t = *REAL(s); double u = t-floor(t)-0.5; if(u0) *ptr=-1+4*u; else *ptr=-1-4*u; Rprintf(The value is %f, *ptr); UNPROTECT(1); return result; } }; It is compiled with R CMD SHLIB source.c If you want C++, then name your file source.cpp SHLIB compiles files with .c extensions with a C compiler, which will not be happy about extern C with flag MAKEFLAGS=CC=g++ If I compile with the default flags I get an error message about an undefined reference to __gxx_personality_v0. However when I call this code from R with test- function(t){ .Call(test,t) } dyn.load(./source.dll) test(0) dyn.unload(./source.dll) then R crashes. I have a vague idea of the issue of calling conventions and was hoping that the __cdecl specifier would force the appropriate convention. I also have Cygwin installed as part of the Python(x,y) distribution but I am assuming that R CMD SHLIB source.c calls the right compiler. What could the problem be? Many thanks, Michael -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/98Uf7u : Rcpp 0.8.1 |- http://bit.ly/c6YnCi : graph gallery collage `- http://bit.ly/bZ7ltC : inline 0.3.5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to take the lower triangular part from a full matrix
Le 17/06/10 06:44, ZZY ZYBOYS a écrit : Dear all: I have a question regarding on how to take the lower triangular part from a full matrix. for example 1 2 3 1 0 0 3 4 5 to 3 4 0 7 8 9 7 8 9 Thanks, Joey Please take at least the time to send a reproducible example on how you make you data, i.e: x - matrix( 1:9, nr = 3, byrow = T ) See ?lower.tri x[ upper.tri(x) ] - 0 Or see ?row and ?col x[ row(x) col(x) ] - 0 Also note that ??triangular finds lower.tri Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/98Uf7u : Rcpp 0.8.1 |- http://bit.ly/c6YnCi : graph gallery collage `- http://bit.ly/bZ7ltC : inline 0.3.5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] tempfile problem
Le 17/06/10 18:59, Duncan Murdoch a écrit : On 17/06/2010 12:43 PM, Ben Madin wrote: G'day all, The documentation for tempfile states : The names are very likely to be unique among calls to tempfile in an R session and across simultaneous R sessions. The filenames are guaranteed not to be currently in use. My problem I think relates to the second part of the sentence, which is the guarantee... and it is being met ... but I need to save the files as .png files, in the same directory, so I am adding the suffix and I suppose therefore the next offering can be unique (as it doesn't have the prefix) I am using a command like : fname - basename(tempfile(nahis, /Library/WebServer/Documents/nahis/tmp)) on a mac, or fname - basename(tempfile(nahis, /htdocs/nahis/tmp)) on a FreeBSD system, as I need to be able to find the file from the web browser up to 24 hours later. and then this_filename - paste(fname, .png, sep = ) and saving the file as this_filename, hence the next call doesn't find it's own suggestion, and starts again. It sounds as though you are doing something strange with the random number seed, because those names are chosen at random, and then checked for uniqueness. If the seed is being reset you could get the same name twice in a row, but otherwise it's very unlikely. (And it's the C library function rand(), not R's RNG that is used.) Is there any alternative filenameing approach I can use to get around this? Do I need to manually scan and reject the name if it matches the names I already have? Should I just digest the current time ? (It's working so far!) If you use the current time, watch out for timer accuracy and fast computers. You may be able to get more than one file created before the next timer tick. I'd suggest that you should generate more than enough filenames once at the start, confirm they're all unique, and then just take them one by one as needed. Alternatively, create the tempfile() as well as the tempfile().png, but this is likely to be really slow if the seed is the same each time, because checking for the existence of the first n tries is going to be slow. Duncan Murdoch Would it not make sense to change the signature of tempfile to this: function (pattern = file, tmpdir = tempdir(), suffix = ) and include the suffix in the does the file exist test ? Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/98Uf7u : Rcpp 0.8.1 |- http://bit.ly/c6YnCi : graph gallery collage `- http://bit.ly/bZ7ltC : inline 0.3.5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error when callin g C-Code
This is not the appropriate list for C-level questions. Please study the posting guide and repost on the right list. Also, you might want to also show how you actually call this from R. Are you by any chance using .External instead of .Call ? Romain Le 15/06/10 23:20, Fabian Zäpernick a écrit : Hi when I call the function below in R, i get the error: Object 'pairlist' can't be converted to 'double'. #includeR.h #includeRdefines.h #includeRmath.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); xNT = NUMERIC_POINTER(NT); xtau = NUMERIC_POINTER(tau); GetRNGstate(); if(xlambda[0] != 0) { while(1) { EVar = rexp(xlambda[0]); sign = sign + EVar; if (sign xT2M[0]) { break; } xtau = Realloc(xtau, i+1, double); xtau[i] = sign; i = i+1; for(j; j ltgrid;j++) { if (xtgrid[j] sign) { xNi[j] = xNT[0]; } { break; } } xNT[0] = xNT[0] + 1; } for(j;j ltgrid;j++) { xNi[j] = xNT[0]; } } PutRNGstate(); UNPROTECT(6); return tau; } -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/98Uf7u : Rcpp 0.8.1 |- http://bit.ly/c6YnCi : graph gallery collage `- http://bit.ly/bZ7ltC : inline 0.3.5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] RegExp question
Le 16/06/10 18:54, Andrej a écrit : Thanks David for your fast reply, but now I realized tat string is of type: class(string) [1] jobjRef attr(,package) [1] rJava so I get an error when i try with gsub or sub: sub(^.+\\t(\\d+)\\n.+$, \\1, string) Error in as.character.default(x) : no method for coercing this S4 class to a vector string is a java object, you can get the character vector like this: string$toString() but I bet there are other methods in the java class that would let you access the information you are after without doing text demangling. Try completion: string$TAB replace TAB by the tab key, you should see the list of java methods associated with the java class. you can also call .jmethods .jmethods( string ) Romain I think that there should be trivial solution, but... Any further idea? Regards, Andrej On Jun 16, 6:47 pm, David Winsemiusdwinsem...@comcast.net wrote: On Jun 16, 2010, at 12:04 PM, Andrej wrote: Dear all, I'm trying to filter out the number of leaves (it should be 1 in the example below) from the following string: string [1] Java-Object{J48 pruned tree\n--\n: 0 (15.0/3.0)\n \nNumber of Leaves : \t1\n\nSize of the tree : \t1\n} Any idea how to do that as simple as possible? Thanks in advance for any advice. ?sub # or ?gsub if you need more than one pattern matched (they are on the same page). This should find the first occurrence of digits following a tab terminated by a line feed and then return only the digits: string- Java-Object{J48 pruned tree\n--\n: 0 (15.0/3.0)\n \nNumber of Leaves : \t1\n\nSize of the tree : \t1\n} sub(^.+\\t(\\d+)\\n.+$, \\1, string) [1] 1 The parens within the search pattern are matched to \\1. Need to double backslashed within patterns. Regards, Andrej -- David Winsemius, MD West Hartford, CT -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/98Uf7u : Rcpp 0.8.1 |- http://bit.ly/c6YnCi : graph gallery collage `- http://bit.ly/bZ7ltC : inline 0.3.5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Highlighting Text in Console
It depends what you mean by console. The package xterm256 on CRAN can do some of that on xterm 256 capable consoles. See http://bit.ly/97cCbX Romain Le 09/06/10 10:50, Steve Brooks a écrit : Anyone know how I can highlight specific words/letters (e.g., bold, or different colour) when displaying text to the console using cat or equivalent? I can change e.g., the colour for everything by loading in a new Rconsole file, but what I really want to do is write hello world to the screen but with the word world highlighted in some way. I've searched the Web, the R manuals and the FAQ's but not found anything yet. Any help greatly appreciated. Thanks. -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/98Uf7u : Rcpp 0.8.1 |- http://bit.ly/c6YnCi : graph gallery collage `- http://bit.ly/bZ7ltC : inline 0.3.5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] minor tick marks
Hello, Perhaps something like: axis( 2, 0:10/10, las = 1, tcl = -.2 ) Romain Le 09/06/10 11:08, Stéphane Adamowicz a écrit : Hi ! I need a plot for data extending over several orders of magnitude on the y axis. The following command generates a nice looking semi-log plot for my data: plot(x,y,log=y,type=l,lty=3, ylim=c(0.01,2),yaxp=c(0.01,1,1),las=1) I would appreciate having also minor tick marks in-between the 3 major ticks obtained with the above command. The minor.tick function in library Hmisc gives an error when applied to log axes. Any solution ? Stéphane _ Stéphane Adamowicz INRA, unité PSH domaine St Paul, site agroparc 84914 Avignon, cedex 9 France stephane.adamow...@avignon.inra.fr tel. +33 (0)4 32 72 24 35 fax. +33 (0)4 32 72 24 32 do not dial 0 when out of France web PSH : http://www.avignon.inra.fr/psh web INRA : http://www.inra.fr/ -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/98Uf7u : Rcpp 0.8.1 |- http://bit.ly/c6YnCi : graph gallery collage `- http://bit.ly/bZ7ltC : inline 0.3.5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R with Emacs
Le 04/06/10 12:55, dhanush a écrit : I want to know how Emacs works with R. can anyone provide me a link or manual to read? Thank you http://lmgtfy.com/?q=R+emacs The first link is what you want. Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/c6YnCi : graph gallery collage |- http://bit.ly/bZ7ltC : inline 0.3.5 `- http://bit.ly/8YUsiC : highlight 0.2-0 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sig for R and C++
Also, in the Rcpp-devel mailing list: https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel we do talk a lot about R and C++, mainly because that is what Rcpp is all about. Le 03/06/10 21:21, Marc Schwartz a écrit : On Jun 3, 2010, at 2:10 PM, Erin Hodgess wrote: Dear R People: Is there a sig for people using R and C++, please? Thank you in advance, Sincerely, Erin That subject matter would tend to go to R-Devel: https://stat.ethz.ch/mailman/listinfo/r-devel The full list of official R related lists is at: https://stat.ethz.ch/mailman/listinfo/ The Posting Guide also has a question: Which list: R-help, R-devel, or Bioconductor? with some guidance on this point. HTH, Marc Schwartz -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/c6YnCi : graph gallery collage |- http://bit.ly/bZ7ltC : inline 0.3.5 `- http://bit.ly/8YUsiC : highlight 0.2-0 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using the name of an argument in a function
Hi, This is a dangerous game you are playing. I would play with the call stack, i.e sys.calls : setMethod(fun,character, definition = function(y,x,...){ stack - sys.calls( ) stack.fun - Filter( function(.) .[[1]] == as.name(fun), stack ) nameOfY - deparse( stack.fun[[1]][[2]] ) cat(name is ',nameOfY, '\n , sep = ) } ) titi - aze fun( titi ) name is 'titi' fun( letters[1:4] ) name is 'letters[1:4]' Romain Le 25/05/10 14:54, cgenolin a écrit : Hi all, In a function, I need to get the name of a variable that has been used to call the function. For example, I want: --- 8 -- toto- 3 fun- function(y){ nameOfY-deparse(substitute(y)) cat(name is ,nameOfY) } fun(toto) # [1] name is toto --- 8 But deparse(substitute(y)) does not work all the time, especially when we use generic function. --- 8 setGeneric(fun,function(y,...){standardGeneric(fun)}) setMethod(fun,numeric, definition = function(y,...){ nameOfY-deparse(substitute(y)) cat(name is ,nameOfY) } ) toto- 4 fun(toto) # name is toto setMethod(fun,character, definition = function(y,x,...){ nameOfY-deparse(substitute(y)) cat(name is ,nameOfY) } ) titi- aze fun(titi) # name is y --- 8 So is there a way to get the name of the variable toto or titi in a way that work in all cases? Christophe -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/cork4b : highlight 0.1-8 |- http://bit.ly/bklUXt : RcppArmadillo 0.2.1 `- http://bit.ly/936ck2 : Rcpp 0.8.0 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] make: Nothing to be done for `all'.
Le 12/05/10 00:23, Elizabeth Lawson a écrit : Why would I want to remove (rm) the file. I am trying to compile it. make thinks : Why would I compile this file, the result is already there First time : rom...@naxos /tmp $ R CMD SHLIB hello.c gcc-4.2 -arch x86_64 -std=gnu99 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -I/usr/local/include-fPIC -g -O3 -Wall -pipe -Wno-variadic-macros -c hello.c -o hello.o gcc-4.2 -arch x86_64 -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o hello.so hello.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation Second time: rom...@naxos /tmp $ R CMD SHLIB hello.c make: Nothing to be done for `all'. Does that help ? Romain BTW, your second post is more useful than the first one as you actually partly follow the posting guide and show some example code. For the file hello2.c /* hello.c: display a message on the screen */ #includestdio.h main() { printf(hello, world\n); } I used gcc hello2.c and it works fine. But fort eh file hello.c #includeR.h void hello(int *n) { int i; for(i=0; i *n; i++) { Rprintf(Hello, world!\n); } } I try R CMD SHLIB hello.c and I ge tthe error make: Nothing to be done for `all'. Why does one compile and the other not? -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/9aKDM9 : embed images in Rd documents |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] make: Nothing to be done for `all'.
Le 11/05/10 04:16, Elizabeth Lawson a écrit : Hi, I just bought new macbook pro 10.6.3. I am trying to use some old c code that used to work. I tried to recompile the code. In the directory with code I used R CMD SHLIB hello.c and get the error make: Nothing to be done for `all'. I have tried reinstalling Xcode and R but I am still having this problem. Any suggestions? You can try $ rm hello.o hello.so Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/9aKDM9 : embed images in Rd documents |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] make: Nothing to be done for `all'.
Le 11/05/10 13:40, Elizabeth Lawson a écrit : When I try $ rm hello.o hello.so I get the error -bash: $: command not found What does that mean? Did you actually type the '$' ? You should not have. -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/9aKDM9 : embed images in Rd documents |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error in RImageJ
This is a known issue. You can: - ask apple to fix it - use R embedded into a java application, e.g. JGR Romain Le 08/05/10 03:49, Fredy Mejía a écrit : Hello everybody, I'm running R under Mac OS 10.6.3 on a MacBook 2.16 GHz Intel Core 2 Duo. I've recently installed R 2.11.0 and the RImageJ library v. 0.1-142. When trying to follow the example given in the package manual and I get the following error: download.file( http://www.google.fr/intl/en_en/images/logo.gif;, dest = google.gif ) trying URL 'http://www.google.fr/intl/en_en/images/logo.gif' Content type 'image/gif' length 8558 bytes opened URL == downloaded 8558 bytes image = IJ$openImage( google.gif ) Error in .jcall(RJavaTools, Ljava/lang/Object;, invokeMethod, cl, : java.lang.InternalError: Can't start the AWT because Java was started on the first thread. Make sure StartOnFirstThread is not specified in your application's Info.plist or on the command line starting httpd help server ... done Can someone help me figuring out what this means and how to solve the problem? Thanks in advance. Fredy -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/9aKDM9 : embed images in Rd documents |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Split a vector by NA's - is there a better solution then a loop ?
Maybe this : foo - function( x ){ + idx - 1 + cumsum( is.na( x ) ) + not.na - ! is.na( x ) + split( x[not.na], idx[not.na] ) + } foo( x ) $`1` [1] 2 1 2 $`2` [1] 1 1 2 $`3` [1] 4 5 2 3 Romain Le 29/04/10 09:42, Tal Galili a écrit : Hi all, I would like to have a function like this: split.vec.by.NA- function(x) That takes a vector like this: x- c(2,1,2,NA,1,1,2,NA,4,5,2,3) And returns a list of length of 3, each element of the list is the relevant segmented vector, like this: $`1` [1] 2 1 2 $`2` [1] 1 1 2 $`3` [1] 4 5 2 3 I found how to do it with a loop, but wondered if there is some smarter (vectorized) way of doing it. Here is the code I used: x- c(2,1,2,NA,1,1,2,NA,4,5,2,3) split.vec.by.NA- function(x) { # assumes NA are seperating groups of numbers #TODO: add code to check for it number.of.groups- sum(is.na(x)) + 1 groups.end.point.locations- c(which(is.na(x)), length(x)+1) # This will be all the places with NA's + a nubmer after the ending of the vector group.start- 1 group.end- NA new.groups.split.id- x # we will replace all the places of the group with group ID, excapt for the NA, which will later be replaced by 0 for(i in seq_len(number.of.groups)) { group.end- groups.end.point.locations[i]-1 new.groups.split.id[group.start:group.end]- i group.start- groups.end.point.locations[i]+1 # make the new group start higher for the next loop (at the final loop it won't matter } new.groups.split.id[is.na(x)]- 0 return(split(x, new.groups.split.id)[-1]) } split.vec.by.NA(x) Thanks, Tal -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/9aKDM9 : embed images in Rd documents |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] JRI API: sourcing from Java String
Le 28/04/10 15:40, Ralf B a écrit : Hi all, I have been using 'source(filename)' to load R code from a file object. However, now I have a special case where I don't have a file since I am loading an R script from a Jar file. I would like to avoid creating temporary files. Is there a way to use the 'source' command with a Java String? Are there any other, better ways to do that? Ralf You can parse the String using parse and then eval the result using eval. You can do both at once using parseAndEval You can assign the String to some R variable ( say FOO) using assign, and then in R do something like : eval( parse( text = FOO ) ) Questions about JRI, rJava, REngine, etc ... usually belong to the stats-rosuda-devel mailing list: http://mailman.rz.uni-augsburg.de/mailman/listinfo/stats-rosuda-devel Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/9aKDM9 : embed images in Rd documents |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error message when trying to install Rcmdr
Did you try to follow the advice R gives you 24 times ? Le 17/04/10 11:57, thedoctor81877 a écrit : I am trying to install Rcmdr on my ubuntu machine, but keep getting the following error messages: ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ ERROR: failed to lock directory ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10’ for modifying Try removing ‘/home/thedoctor/R/i486-pc-linux-gnu-library/2.10/00LOCK’ Any help at solving this problem would greatly be appreciated. -Michael -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/9aKDM9 : embed images in Rd documents |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Inline Package: void vs return type functions
Le 13/04/10 15:46, satu a écrit : Dear all, After having a look at the inline package and also going through the Rcpp package which is tighty related to it, it came to me this question: no. 1) my C/ C++ code has a return type (let say a double[][] or a user define class) 2) I am working with an extensive library built by someone else and I don't have the time/knowledge to change it by means of working with pointer variables in order to avoid the return sentence,,, Please at least find the time to read Writing R Extensions question A: can I use the -inline- cfunction without resorting to the Rcpp functionality? yes. inline knowns about Rcpp but can work on its own. you need Rcpp if you use the Rcpp argument of cfunction. -- if this is true, question A2: do I need to go deep in the source code coming from the library (that I am trying to use) to perform the interface through the Rcpp classes? no. questionB: is it true that the working with the -inline- function you have to have only void return type code? Which interface are we talking about ? .C, .Call ? All the documentation is available in writing R extensions. In .Call, which is the preferred way when you use Rcpp, the return type must be SEXP or whatever that can be implicitely converted to SEXP. Many classes in Rcpp do have implicit conversion to SEXP (Rcpp::IntegerVector, Rcpp::List, etc ...) -- if this is false, questionB2: do you have a simple example of this? ?cfunction Writing R extensions Many thanks Sergio Barrios -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/9aKDM9 : embed images in Rd documents |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] I can´t run the example shown in the inline pa ckage
What happened to the line that contained R CMD SHLIB ? This is the bit that compiles the code. On windows (you were asked to tell us that you are running windows, both through the posting guide and from my previous email) you need to install the same tools that one needs for building a package. See http://cran.r-project.org/doc/manuals/R-admin.html#The-Windows-toolset Romain Le 09/04/10 15:11, satu a écrit : Dear Romain, I am working with a PC with Windows-XP I do have Rtools installed and running the code you propose, this is what I get as a result: code- '#includeRdefines.h\nSEXP f(){\n return R_NilValue ; }' writeLines( code, test.c ) dyn.load( test.so ) Error in inDL(x, as.logical(local), as.logical(now), ...) : unable to load shared library 'C:/Documents and Settings/L01359.BCRA/Mis documentos/R/test.so': LoadLibrary failure: No se puede encontrar el módulo especificado. .Call( f ) Error in .Call(f) : C symbol name f not in load table Sergio -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/9aKDM9 : embed images in Rd documents |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Okay, here is what I am doing
Do you have the tools ? What operating system are you using ? What happens if you do this: code - '#include Rdefines.h\nSEXP f(){\n return R_NilValue ; }' writeLines( code, test.c ) system( R CMD SHLIB test.c ) dyn.load( test.so ) .Call( f ) Romain Le 08/04/10 20:28, satu a écrit : All is done in R 2.10.1 wiht the package inline version 0.3.4,,, this are the packages that I have loaded into the workspace search() [1] .GlobalEnvpackage:inlinepackage:stats package:graphics package:grDevices package:datasets package:rcom [8] package:rscproxy package:utils package:methods Autoloads package:base This is pure copy and paste from the PDF file x- as.numeric(1:10) n- as.integer(10) x [1] 1 2 3 4 5 6 7 8 9 10 n [1] 10 sigSq- signature(n=integer, x=numeric) codeSq- + for (int i=0; i *n; i++) { + x[i] = x[i]*x[i]; + } sigSq n x integer numeric codeSq [1] \nfor (int i=0; i *n; i++) {\nx[i] = x[i]*x[i];\n} sigQd- signature(n=integer, x=numeric) codeQd- + squarefn(n, x); + squarefn(n, x); + sigQd n x integer numeric codeQd [1] \nsquarefn(n, x);\nsquarefn(n, x);\n fns- cfunction( list(squarefn=sigSq, quadfn=sigQd), + list(codeSq, codeQd), + convention=.C) ERROR(s) during compilation: source code errors or compiler configuration errors! Program source: 1: #includeR.h 2: 3: 4: extern C { 5: void squarefn ( int * n, double * x ); 6: } 7: 8: void squarefn ( int * n, double * x ) { 9: 10: for (int i=0; i *n; i++) { 11: x[i] = x[i]*x[i]; 12: } 13: } 14: extern C { 15: void quadfn ( int * n, double * x ); 16: } 17: 18: void quadfn ( int * n, double * x ) { 19: 20: squarefn(n, x); 21: squarefn(n, x); 22: 23: } Error in compileCode(f, code, language, verbose) : Compilation ERROR, function(s)/method(s) not created! Following the example shown in this PDF,,, after the fns- cfunction( ,,, ) follows: squarefn- fns[[squarefn]] quadfn- fns[[quadfn]] squarefn(n, x)$x quadfn(n, x)$x but the compile error shows up right after the cfunction(,,,) sentence. -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/9aKDM9 : embed images in Rd documents |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Adding RcppFrame to RcppResultSet causes segmentation fault
The thread has been handled in Rcpp-devel. Rob posted there 7 minutes after posting on r-help. FWIW, I think the problem is fixed on the Rcpp 0.7.11 version (on cran incoming) Romain Le 01/04/10 17:47, Matthew Dowle a écrit : Rob, Please look again at Romain's reply to you on 19th March. He informed you then that Rcpp has its own dedicated mailing list and he gave you the link. Matthew R_help Helprhelp...@gmail.com wrote in message news:ad1ead5f1003291753p68d6ed52q572940f13e1c0...@mail.gmail.com... Hi, I'm a bit puzzled. I uses exactly the same code in RcppExamples package to try adding RcppFrame object to RcppResultSet. When running it gives me segmentation fault problem. I'm using gcc 4.1.2 on redhat 64bit. I'm not sure if this is the cause of the problem. Any advice would be greatly appreciated. Thank you. Rob. int numCol=4; std::vectorstd::string colNames(numCol); colNames[0] = alpha; // column of strings colNames[1] = beta; // column of reals colNames[2] = gamma; // factor column colNames[3] = delta; // column of Dates RcppFrame frame(colNames); // Third column will be a factor. In the current implementation the // level names are copied to every factor value (and factors // in the same column must have the same level names). The level names // for a particular column will be factored out (pardon the pun) in // a future release. int numLevels = 2; std::string *levelNames = new std::string[2]; levelNames[0] = std::string(pass); // level 1 levelNames[1] = std::string(fail); // level 2 // First row (this one determines column types). std::vectorColDatum row1(numCol); row1[0].setStringValue(a); row1[1].setDoubleValue(3.14); row1[2].setFactorValue(levelNames, numLevels, 1); row1[3].setDateValue(RcppDate(7,4,2006)); frame.addRow(row1); // Second row. std::vectorColDatum row2(numCol); row2[0].setStringValue(b); row2[1].setDoubleValue(6.28); row2[2].setFactorValue(levelNames, numLevels, 1); row2[3].setDateValue(RcppDate(12,25,2006)); frame.addRow(row2); RcppResultSet rs; rs.add(PreDF, frame); -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 `- http://tr.im/O1wO : highlight 0.1-5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error using Rcpp
Le 25/03/10 13:16, Abhisek a écrit : Hi, Im not sure if this is the right place to post this. It is not. The Rcpp-devel mailing list is the right place: https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel I am using Xubuntu Karmic Koala and am trying to use the Rcpp package. I am testing it using a simple code that takes in a vector and adds 1 to each element: #includeRcpp.h // This file takes in a vector and adds one to each entry RcppExport SEXP addone(SEXP vec){ // create a local copy of vec Rcpp::NumericVector orig(vec); // create an output vector Rcpp::NumericVector vecout(orig.size()); for(i=0;iorig.size();i++) { vecout[i] = orig[i]+1; } Rcpp::Pairlist res(Rcpp::Named(result,vecout),Rcpp::Named(original,orig)); return res; } You need some flags set up : export PKG_LIBS=`Rscript -e Rcpp:::LdFlags()` export PKG_CXXFLAGS=`Rscript -e Rcpp:::CxxFlags()` R CMD SHLIB addone.cpp also, your code is not correct since the i variable is not declared, so I get this when I try to compile it: addone.cpp: In function ‘SEXPREC* addone(SEXPREC*)’: addone.cpp:12: error: ‘i’ was not declared in this scope make: *** [addone.o] Error 1 The inline package can help you with this when prototyping your code, check the cfunction in the inline package, specifically its arguments verbose and Rcpp. Personally I would code this using stl algorithms rather than raw looping: #include Rcpp.h template typename T inline T add_one( T x){ return x + 1 ; } // This file takes in a vector and adds one to each entry RcppExport SEXP addone(SEXP vec){ // original object Rcpp::NumericVector orig(vec); // output vector Rcpp::NumericVector vecout(orig.size()); std::transform( orig.begin(), orig.end(), vecout.begin(), add_onedouble ) ; return vecout ; } or maybe you don't even have to write the tedious add_one template and you can do it like this: #include Rcpp.h // This file takes in a vector and adds one to each entry RcppExport SEXP addone(SEXP vec){ // original object Rcpp::NumericVector orig(vec); // output vector Rcpp::NumericVector vecout(orig.size()); std::transform( orig.begin(), orig.end(), vecout.begin(), std::bind2nd( std::plusdouble(), 1.0 ) ) ; return vecout ; } I then try to use - R CMD SHLIB addone.cpp that didnt work. the error said there was no such file - Rcpp.h . Then i came across Dirk Eddelbeutel's beamer presentation and followed the suggestion to copy Rcpp.h to /usr/loca/include and libRcpp.so to /usr/local/lib Then i tried R CMD SHLIB addone.cpp again but got many errors. Here is a small selection: /usr/local/include/Rcpp.h:34:32: error: RcppDatetimeVector.h: No such file or directory /usr/local/include/Rcpp.h:35:23: error: RcppFrame.h: No such file or directory /usr/local/include/Rcpp.h:36:26: error: RcppFunction.h: No such file or directory /usr/local/include/Rcpp.h:37:22: error: RcppList.h: No such file or directory could someone help? im afraid im new both to linux and Rcpp! best, abhisek -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 `- http://tr.im/O1wO : highlight 0.1-5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R script From PHP
Hello, You might like the php client to Rserve that is part of the next version of Rserve. see http://www.rforge.net/Rserve/svn.html install the last snapshot, and check the client/php/simple.php file If you decide to go this way, then I'd suggest you use the stats-rosuda-devel mailing list for further questions. Romain Le 23/03/10 04:27, sanchow a écrit : Hello, I am having the same problem. My webmaster is not ready to install R on the web server. Is there a way to run R on a remote linux cluster and POST results from the remote server to my website? I am sorry if this is more of a PHP question. Thank you and Any help appreciated. S -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 `- http://tr.im/O1wO : highlight 0.1-5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Embed R code in C++
Le 23/03/10 13:34, mans a écrit : No, I didnt install Rcpp but i have R 2.10.1 already installed. If you want to use RInside, you need Rcpp. This is what dependencies are for. you can install Rcpp from R : install.packages( Rcpp ) What's the difference with Rinside and Rcpp? Rcpp defines a set of classes to ease writing C++ code in R packages. you can think it as c++ inside R. RInside facilitates embedding R in a c++ application, you can think it as R inside c++. Do i need both to embed R code in C++ file or just one of them ? You don't __need__ any of them, but thy will make the process easier. Could you tell me where can i get Rcpp pkg? cran, but google knows and would have given you the answer more quickly. How can i Install it because i dont know how to compile a source file on the terminal. Thanks very much for your help. -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 `- http://tr.im/O1wO : highlight 0.1-5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Embed R code in C++
Hello, I don't know specifics of Xcode, etc ... it looks nice but I have not used it myself yet. There seems to be issues on OSX with the current released version of RInside (we will release 0.2.2 soon), so I would suggest you download and install the next version of RInside from r-forge: $ svn checkout svn://svn.r-forge.r-project.org/svnroot/rinside $ cd rinside $ R CMD INSTALL pkg Then you can find example application: $ cd pkg/inst/examples/standard $ make $ ./rinside_sample0 Hello, world! There are several examples in this directory and you can use the Makefile as a template to get the bits and pieces (link against Rcpp and RInside libraries, include path, etc ...) If you have further questions a bout RInside, I would encourage you to use the Rcpp-devel mailing list on r-forge: https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel If you have questions about xcode, ..., then a better place might be the r-sig-mac mailing list: https://stat.ethz.ch/mailman/listinfo/r-sig-mac Romain Le 22/03/10 16:25, mans a écrit : Hi, Can anyone tell me how to embed R code in a C++ file. I am actually using a mac running on the OSX 10.6.2 and the IDE Xcode Version 3.2 and I would like to embed the basic function like geometric, binomial, normal and hyper geometric distributions in a sample cpp file. I heard about the library RInside and i have downloaded the source code for mac but i do not know how to build it in order to use it with my IDE XCode. Could anyone help me step by step because I am new in programming to show me how to get this done? Thanks for your help. Mans. -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 `- http://tr.im/O1wO : highlight 0.1-5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating Rcpp RcppDatetime from string with millisecond
Hello, Rcpp has a dedicated mailing list where such questions are appropriate. https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel Please augment your email with some code examples of what you tried and repost on Rcpp-devel. Romain Le 19/03/10 00:45, R_help Help a écrit : Hi, I was trying to generate RcppDatetime from a string. The main problem for me is that my string contains millisecond. I saw that RcppDatetime takes in double of seconds since epoch. I try to generate a double using boost but has no success. I'm wondering if you have any sample snippet? The string looks like: 2010-03-18 15:50:51.232 Secondly, what time zone RcppDatetime is based on? Is it local machine time zone? And if I have a need to convert time zone, is there any tool at hand I can use? Or I have to resort to something like boost again? Thank you so much in advance. Rob -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 `- http://tr.im/O1wO : highlight 0.1-5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Can't setup rJava under ubuntu
Hi, did you try to install rJava as an ubuntu package: http://packages.ubuntu.com/lucid/math/r-cran-rjava Romain Le 19/03/10 17:38, fgrazi a écrit : When I try to install rJava, I get the following error: install.packages('rJava') ... checking whether siglongjmp is declared... yes checking Java support in R... present: interpreter : '/usr/bin/java' archiver: '/usr/bin/jar' compiler: '/usr/bin/javac' header prep.: '/usr/bin/javah' cpp flags : '-I/usr/lib/jvm/java-6-openjdk/jre/../include' java libs : '-L/usr/lib/jvm/java-6-openjdk/jre/lib/i386/client -L/usr/lib/jvm/java-6-openjdk/jre/lib/i386 -L/usr/lib/jvm/java-6-openjdk/jre/../lib/i386 -L -L/usr/java/packages/lib/i386 -L/usr/lib/jni -L/lib -L/usr/lib -ljvm' checking whether JNI programs can be compiled... configure: error: Cannot compile a simple JNI program. See config.log for details. e a simple JNI program. See config.log for details. Well, there is no /usr/bin folder on my computer and I have no idea of why install program tries to use it. No way to use R CMD javareconf. As a superuser I get the message that tere is no java interpreter, as a normal uset I get the right configuration, but then So I manually edited /etc/R/Makeconf ( So install abends and I try to use R CMD javareconf and I still get the error: Cannot compile a simple JNI program. See config.log for details. e a simple JNI program. See config.log for details. But I can't find any config.log file so I am unable to understand what is the error! Can the log be redirected to console? Any suggestion on how to find config.log? Any suggestion on having R working with java under Ubuntu? Any idea of where I can find some kind of documentation? -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 `- http://tr.im/O1wO : highlight 0.1-5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] C# DLL Library
The link works fine for me on firefox, chrome and safari. Other ways to get to it are: - search rcpp mailing list on google. - go to r-forge (again google knows where), click on the Rcpp - R/C++ interface, click on the Lists tab, click on subscribe, etc ... Le 17/03/10 04:42, Jeremie Smaga a écrit : I found the problem for the package that wasn't found... My R version was 2.9. Sorry about that. However, I would really appreciate it if you could let me know where I could find the mailing list... Thanks, Jeremie On Tue, Mar 16, 2010 at 6:56 PM, Romain Francois rom...@r-enthusiasts.comwrote: Hello, disclaimer: I don't know C# at all and how it might connect to c++, etc ... For an introductory ride about Rcpp, you can consult the Rcpp-introduction vignette which you can download from the cran page of Rcpp or if you have it installed, you can just do: vignette( Rcpp-introduction, package = Rcpp ) For semi-self-explanatory code examples, you can consult our unit tests: system.file( unitTests, package = Rcpp ) For more questions, we have a dedicated mailing list: https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel Romain Le 16/03/10 11:43, Jeremie Smaga a écrit : Hello Richard, Thanks for the tips. I was aware of the R(D)COM. In the last public version, there is now splash screen appearing which is kind of boring so I think I need to buy it or something. Anyway, I think the idea was to create a common CORE library that can be used from C# and from R. So I think I'll have a look at RCPP which looks to be the best solution. Have you tried it already? Do you know any good tutorial for this package? Thanks, Jeremie On Tue, Mar 16, 2010 at 5:23 PM,richard.cot...@hsl.gov.uk wrote: I would like to develop a core library which I will be using both from R and from C#. - Writing the DLL freely in C# and then create a wrapper? - Writing it in C++ - Writing it in C, the other options are really not good ideas. As far as I know, there currently is no way to call .NET code from R. If you want a library that can be called from both a .NET environment and from R, then writing it in C or C++ is likely your best bet. Alternatively, you can run R code from within .NET using the rcom package. There's an example in F# here (what's true for F# is true for C#). http://cs.hubfs.net/blogs/thepopeofthehub/archive/2007/11/06/FSharpWithR.aspx See ?.C for calling C code, and the rcpp package for an interface to C++ code. Choosing between those two languages mostly depends on whether on not your library is especially suited to object oriented programming or not. Regards, Richie. Mathematical Sciences Unit* **HSL*http://www.hsl.gov.uk/contact-us.htm r-help-boun...@r-project.org wrote on 16/03/2010 09:04:54: Good afternoon everybody, I am sorry, this question might look trivial to some of you, but I read quite a lot of stuff about package creation and I would like a bit of you advices. I read that it was possible to import DLL to R. The thing is, I am not sure that the DLL created with C# will be compatible. I still have not implemented anything, so if it is only a matter of method signatures, I can make sure everything fits. Otherwise, I could use a C++ DLL, but I don't know if it is really recommended. (In fact, I would love to be able to develop it in Visual Studio because it is where I developed the rest of my platform). So, what would you advise? Thanks, -- Jeremie Smaga -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 `- http://tr.im/O1wO : highlight 0.1-5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] C# DLL Library
Hello, disclaimer: I don't know C# at all and how it might connect to c++, etc ... For an introductory ride about Rcpp, you can consult the Rcpp-introduction vignette which you can download from the cran page of Rcpp or if you have it installed, you can just do: vignette( Rcpp-introduction, package = Rcpp ) For semi-self-explanatory code examples, you can consult our unit tests: system.file( unitTests, package = Rcpp ) For more questions, we have a dedicated mailing list: https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel Romain Le 16/03/10 11:43, Jeremie Smaga a écrit : Hello Richard, Thanks for the tips. I was aware of the R(D)COM. In the last public version, there is now splash screen appearing which is kind of boring so I think I need to buy it or something. Anyway, I think the idea was to create a common CORE library that can be used from C# and from R. So I think I'll have a look at RCPP which looks to be the best solution. Have you tried it already? Do you know any good tutorial for this package? Thanks, Jeremie On Tue, Mar 16, 2010 at 5:23 PM,richard.cot...@hsl.gov.uk wrote: I would like to develop a core library which I will be using both from R and from C#. - Writing the DLL freely in C# and then create a wrapper? - Writing it in C++ - Writing it in C, the other options are really not good ideas. As far as I know, there currently is no way to call .NET code from R. If you want a library that can be called from both a .NET environment and from R, then writing it in C or C++ is likely your best bet. Alternatively, you can run R code from within .NET using the rcom package. There's an example in F# here (what's true for F# is true for C#). http://cs.hubfs.net/blogs/thepopeofthehub/archive/2007/11/06/FSharpWithR.aspx See ?.C for calling C code, and the rcpp package for an interface to C++ code. Choosing between those two languages mostly depends on whether on not your library is especially suited to object oriented programming or not. Regards, Richie. Mathematical Sciences Unit* **HSL*http://www.hsl.gov.uk/contact-us.htm r-help-boun...@r-project.org wrote on 16/03/2010 09:04:54: Good afternoon everybody, I am sorry, this question might look trivial to some of you, but I read quite a lot of stuff about package creation and I would like a bit of you advices. I read that it was possible to import DLL to R. The thing is, I am not sure that the DLL created with C# will be compatible. I still have not implemented anything, so if it is only a matter of method signatures, I can make sure everything fits. Otherwise, I could use a C++ DLL, but I don't know if it is really recommended. (In fact, I would love to be able to develop it in Visual Studio because it is where I developed the rest of my platform). So, what would you advise? Thanks, -- Jeremie Smaga -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 `- http://tr.im/O1wO : highlight 0.1-5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how can I look at .Internal(model.matrix(t, data))?
Also see Uwe's article in R news : Accessing the source : http://cran.r-project.org/doc/Rnews/Rnews_2006-4.pdf On 03/09/2010 09:22 AM, Peter Ehlers wrote: I imagine it's in https://svn.r-project.org/R/trunk/src/main/model.c -Peter Ehlers On 2010-03-05 12:43, Werner W. wrote: Hi, I would like to see how model.matrix expands factor column to a set of dummy columns. I think that is done int .Internal(model.matrix(t, data)) which is called from model.matrix.default. But I have not idea how I can look at this function. How can I get to such internal functions? Thanks so much! Werner -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 `- http://tr.im/O1wO : highlight 0.1-5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Writing own simulation function in C
collecter to munch the data we're pointing to before we get a chance to use it. After finding the stats namespace, the second operation is to set up the call back to the R function ruinf()-- this is started by creating a vector of type language that has a length of 4-- one slot for the function name and then three more slots because runif takes three arguments. Next, the slots of the LANGSXP are filled- first by locating the name of the function we wish to call using findFun() and then by filling in the arguments. The assignment of each argument is followed by a call to SET_TAG which tags the argument with it's name in the R function. Basically, lines 18-29 construct an R function call of the form: runif( n = n, min = min, max = max ) Next, a SEXP is created to hold the results of the function call that was constructed. The variable is then assigned the results of the function call inside a PROTECT() Finally, UNPROTECT(3) is called before the results are returned to R. This is don because we called PROTECT() 3 times. If you don't call UNPROTECT(), you will see warnings about a Stack Imbalance when running your code in R. It is worth noting that I am being incredibly verbose with lines 15-36, I could have replaced them with: see: http://gist.github.com/323498#file_my_runif_concise.c In the case above, lang4() provides a shortcut for building a LANGSXP with 4 slots and the call arguments are matched by position. I showed the long version in case you want to execute a call with more than 3 arguments or you need to execute a call using key=value matching. Finally, you need to add one more routine that causes the dynamic library to be loaded when the R package is loaded. Since the package doesn't have a namespace, we'll use the function .First.lib() and place it in RtoC/R/zzz.R: see: http://gist.github.com/323498#file_zzz.r If you add a namespace to your package, you will need to use .onLoad() instead of .First.lib(). Now build and install the package: R CMD build RtoC R CMD INSTALL RtoC_0.1.tar.gz You should be able to execute the following in R: library( RtoC ) myRunif( 10 ) [1] 0.8072035 0.3978969 0.6492380 0.3614537 0.9150126 0.7287221 0.4242656 [8] 0.9401839 0.8275597 0.7270001 myRunif( 10, -10, 10 ) [1] 0.669904 -7.603356 -6.632470 6.753585 -9.424831 8.758971 -4.430569 [8] 3.737836 -5.297374 -9.968060 Happy hacking! -Charlie - Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 `- http://tr.im/O1wO : highlight 0.1-5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Running complete R script from Java
You can source the script, e.g run the command : eval( source( ' + script + ') ) ; Questions about rJava/JRI are better on the stats-rosuda-devel mailing list: http://mailman.rz.uni-augsburg.de/mailman/listinfo/stats-rosuda-devel Romain On 03/05/2010 03:51 AM, Ralf B wrote: Is it possible to run a R script from Java (via JRI (part of rJava): http://www.rforge.net/rJava/) without adding it line by line into a JRI java application? Ralf -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 `- http://tr.im/O1wO : highlight 0.1-5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Double Colors in Main
See this thread : http://finzi.psych.upenn.edu/Rhelp10/2009-January/185693.html On 03/02/2010 02:18 PM, Lorenzo Isella wrote: Dear All, Consider the following trivial code snippet rm(list=ls()) name_vec - c(color1, color2) pdf(test_color.pdf) plot(seq(5), seq(5), main=paste(name_vec[1], and ,name_vec[2], sep=)) dev.off() What I would like to achieve is rather simple to explain, but it is giving me a headache: how can I have two colors in main? Let us say that I would like 'color1' to be blue and 'color2' to be black. Many thanks Lorenzo -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 `- http://tr.im/O1wO : highlight 0.1-5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] colour highlighting inputs and outputs in the R terminal?
On 02/23/2010 03:02 PM, Marc Schwartz wrote: On Feb 23, 2010, at 7:05 AM, Liviu Andronic wrote: Dear all Is it possible to get basic colour highlighting for inputs and outputs in the R terminal? I am looking for something similar to what GUIs provide, such as JGR and (I think) the Windows R GUI: colouring all inputs in red, and all outputs in blue. All this in a colour-aware console (in my case, on Linux). I've been looking into xterm256 and highlight, but I am sofar unable to do with them what I would need. The closest I get to is with style() in xterm256: require(xterm256) cat( style( hello world, bg = black, fg = blue), \n ) hello world The text will appear blue. What I would want to achieve, however, is to be able to define some global options for input fg and bg colours, and output fg and bg colours. Then, for any command that I would execute, say `mean(1:5)', I would get: mean(1:10) ##in red [1] 5.5 ##in blue summary(1:5) ##in red Min. 1st Qu. MedianMean 3rd Qu.Max. ##in blue 1 2 3 3 4 5 ##in blue Does anyone know a way to do this? Thank you Liviu Hi Liviu, I was not aware of Romain's xterm256 package, but from a quick review of the manual, it would appear to not support an automated syntax highlighting capability. One seems to need to explicitly print output to the console using his functions to be able to colorize it. That's right, xterm256 is for manual formatting. What Liviu wants is not impossible to achieve --- it has been done for python for example [1] --- but would require some considerable effort, using for example ncurses [2] . Romain [1] http://bpython-interpreter.org/home/ [2] http://www.gnu.org/software/ncurses/ Having used R on Windows, Linux and now OSX over the past 8+ years, I initially used ESS (http://ess.r-project.org/) on Windows and stayed with it on each subsequent platform. The terminal consoles are fine for quick and dirty coding and I will frequently use the terminal on OSX to test code for replying to a post here. But for routine use, I am in ESS, which provides syntax highlighting and so much more. On Windows and OSX, there are GUI interfaces that members of R Core have kindly provided which provide colorized output, but there is no parallel on Linux, other than third party options. Rather than using the terminal, I would recommend that you give serious consideration to using a full blown text editor, many of which already support R syntax highlighting and of course typical text editing features. In the most basic implementation, you can write your code in the editor and copy and paste it to the R console. With tighter integration, such as ESS, you can have split windows, with R code in one frame (say the upper half of the application window) and the R console running in an other one (say the lower half), both of which support R syntax highlighting. With a quick few keystrokes, you can submit the entire R code frame to the console or highlight sections of code and just submit that. Beyond that there is a lot other functionality (version control, LaTeX support, etc.) available that makes ESS an extremely efficient environment to use. If you prefer to not use or learn Emacs, there are other editors available such as Vim, Bluefish, Eclipse and many others available for Linux, some of which are listed here: http://www.sciviews.org/_rgui/projects/Editors.html JGR is also available for Linux: http://jgr.markushelbig.org/JGR_on_Linux.html HTH, Marc Schwartz -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 `- http://tr.im/O1wO : highlight 0.1-5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] What is the difference between expression and quote whenused with eval()?
On 02/21/2010 01:45 AM, blue sky wrote: On Sat, Feb 20, 2010 at 2:40 AM, Romain Francois romain.franc...@dbmail.com wrote: On 02/19/2010 10:31 PM, William Dunlap wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of blue sky Sent: Friday, February 19, 2010 12:11 PM To: Peter Dalgaard Cc: r-h...@stat.math.ethz.ch Subject: Re: [R] What is the difference between expression and quote whenused with eval()? On Fri, Feb 19, 2010 at 12:39 PM, Peter Dalgaard p.dalga...@biostat.ku.dkwrote: blue sky wrote: I made the following example to see what are the difference between expression and quote. But I don't see any difference when they are used with eval()? Could somebody let me know what the difference is between expression and quote? Expressions are vectors of unevaluated expressions, so one difference is that expressions can have more than one element. Another difference is more subtle: objects of mode expression are better at retaining their identity as an unevaluated expression eval(substitute(2+x,list(x=expression(pi Error in 2 + expression(pi) : non-numeric argument to binary operator eval(substitute(2+x,list(x=quote(pi [1] 5.141593 The really convincing application of this escapes me for the moment, but the gist of it is that there are cases where a quoted expression may blend in a bit too seemlessly when using computing on the language. Also, expression objects are more easy to recognize programmeatically, quote() may result in objects of mode call, name, or one of the base classes. I want to see how expression(something) and quote(something) are represented in R internally. But it seems that str() doesn't go to that low level. Is there a way to show the internal representation? There is also the internal inspect function : inspect- function(x, ...) .Internal(inspect(x,...)) inspect( expression(log(1), sqrt(2), trunc(pi)) ) @9657560 20 EXPRSXP g0c2 [NAM(2)] (len=3, tl=153865256) @97ab5e8 06 LANGSXP g0c0 [] @92cf3fc 01 SYMSXP g0c0 [MARK,gp=0x4000] log @9709a28 14 REALSXP g0c1 [] (len=1, tl=0) 1 @97aa750 06 LANGSXP g0c0 [] @92cf204 01 SYMSXP g0c0 [MARK,gp=0x4000] sqrt @97099e8 14 REALSXP g0c1 [] (len=1, tl=0) 2 @97aa84c 06 LANGSXP g0c0 [] @92cf15c 01 SYMSXP g0c0 [MARK,gp=0x4000] trunc @9347c38 01 SYMSXP g0c0 [MARK,gp=0x4000] pi Where is the internal inspect documented? Would you please help explain what does '@9657560 20', 'g0c2', 'NAM(2)', 'MARK', 'tl' and 'gp' stand for? Reading R internals gives some clues, otherwise you can read the source, it is only about 200 lines in src/main/inspect.c -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 `- http://tr.im/O1wO : highlight 0.1-5 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] What is the difference between expression and quote whenused with eval()?
On 02/19/2010 10:31 PM, William Dunlap wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of blue sky Sent: Friday, February 19, 2010 12:11 PM To: Peter Dalgaard Cc: r-h...@stat.math.ethz.ch Subject: Re: [R] What is the difference between expression and quote whenused with eval()? On Fri, Feb 19, 2010 at 12:39 PM, Peter Dalgaard p.dalga...@biostat.ku.dk wrote: blue sky wrote: I made the following example to see what are the difference between expression and quote. But I don't see any difference when they are used with eval()? Could somebody let me know what the difference is between expression and quote? Expressions are vectors of unevaluated expressions, so one difference is that expressions can have more than one element. Another difference is more subtle: objects of mode expression are better at retaining their identity as an unevaluated expression eval(substitute(2+x,list(x=expression(pi Error in 2 + expression(pi) : non-numeric argument to binary operator eval(substitute(2+x,list(x=quote(pi [1] 5.141593 The really convincing application of this escapes me for the moment, but the gist of it is that there are cases where a quoted expression may blend in a bit too seemlessly when using computing on the language. Also, expression objects are more easy to recognize programmeatically, quote() may result in objects of mode call, name, or one of the base classes. I want to see how expression(something) and quote(something) are represented in R internally. But it seems that str() doesn't go to that low level. Is there a way to show the internal representation? There is also the internal inspect function : inspect - function(x, ...) .Internal(inspect(x,...)) inspect( expression(log(1), sqrt(2), trunc(pi)) ) @9657560 20 EXPRSXP g0c2 [NAM(2)] (len=3, tl=153865256) @97ab5e8 06 LANGSXP g0c0 [] @92cf3fc 01 SYMSXP g0c0 [MARK,gp=0x4000] log @9709a28 14 REALSXP g0c1 [] (len=1, tl=0) 1 @97aa750 06 LANGSXP g0c0 [] @92cf204 01 SYMSXP g0c0 [MARK,gp=0x4000] sqrt @97099e8 14 REALSXP g0c1 [] (len=1, tl=0) 2 @97aa84c 06 LANGSXP g0c0 [] @92cf15c 01 SYMSXP g0c0 [MARK,gp=0x4000] trunc @9347c38 01 SYMSXP g0c0 [MARK,gp=0x4000] pi Romain I use the following, which shows `name` class(length) for each element of a recursive object and then shows the offspring indented more than the parent. It does not go into the attributes, nor does it try to outwit classes that may have special methods for as.list(), length(), or names(). It is handy for checking operator precedence. str.language- function (object, ..., level=0, name=deparse(substitute(object))) { abbr-function(string, maxlen=25){ if(length(string)1||nchar(string)maxlen) paste(substring(string[1], 1, maxlen), ..., sep=) else string } cat(rep( , level), sep=) if (is.null(name)) name- cat(sprintf(`%s` %s(%d): %s\n, abbr(name), class(object), length(object), abbr(deparse(object if (is.recursive(object)) { object- as.list(object) names- names(object) for(i in seq_along(object)) { str.language(object[[i]], ..., level = level+1, name = names[i]) } } } E.g., str.language(function(x,y=log(10))log(x)/y) `function(x, y = log(10)) ...` function(1): function (x, y = log(10))... `x` name(1): `y` call(2): log(10) `` name(1): log `` numeric(1): 10 `` call(3): log(x)/y `` name(1): / `` call(2): log(x) `` name(1): log `` name(1): x `` name(1): y str.language(expression(log(1), sqrt(2), trunc(pi))) `expression(log(1), sqrt(2...` expression(3): expression(log(1), sqrt(2... `` call(2): log(1) `` name(1): log `` numeric(1): 1 `` call(2): sqrt(2) `` name(1): sqrt `` numeric(1): 2 `` call(2): trunc(pi) `` name(1): trunc `` name(1): pi str.language(quote(log(pi))) `quote(log(pi))` call(2): log(pi) `` name(1): log `` name(1): pi Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com expr=expression(2*3) quo=quote(2*3) eval(expr) str(expr) class(expr) typeof(expr) mode(expr) attributes(expr) eval(quo) str(quo) class(quo) typeof(quo) mode(quo) attributes(quo) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http
Re: [R] executable R script under xp (to avoid migration toward Matlab or C++)
Hello, Maybe RInside [1] can help you embed your R script into a C++ application. Romain [1] http://dirk.eddelbuettel.com/code/rinside.html On 02/15/2010 11:37 AM, PtitBleu wrote: Hello, I discovered R two years ago and thanks to the R-community I managed to write some scripts to analyze my data stored in mysql databases. The only problem is that I am the only one using R in the lab. Colleagues mainly use Matlab (but not with mysql, only with text files) but regularly come to me to get data treated with R-scripts !!!. To allow the use of my scripts by other people, my boss asked me to make executables (.exe) with my scripts or to pay someone (I'm only end-user and not a computer scientist) to translate them into matlab langage (and then into .exe) or into C++ meaning abandoning R. And I don't want to. So is it possible to make executables from R scripts ? It seems it is not the case but I hope I missed a way to do it. Thanks in advance for your answers, Have a nice day, Ptit Bleu. -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/OcQe : Rcpp 0.7.7 |- http://tr.im/O1wO : highlight 0.1-5 `- http://tr.im/O1qJ : Rcpp 0.7.6 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] executable R script under xp (to avoid migration toward Matlab or C++)
On 02/15/2010 01:03 PM, PtitBleu wrote: Thanks to all for your advices. littler is not for xp, isn'it ? Not currently, I'm cc'ing Dirk and Jeff who will surely tell you why not, and what you can do to make it happen. RInside now works happily on windows, and it would not be too hard to emulate littler in C++ using RInside. If this is of interest, you might want to move the discussion to the Rcpp-devel mailing list, where RInside issues are usually discussed. https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel Anyway, I will try to convince my boss to keep R. But I'm not sure that I will be successful (there is a pressure to have a single language for all the scripts and even money for that ...). And for this year I have been registered to a matlab course ... But I will do my best to promote R !!! Thanks again, Ptit Bleu. -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/OcQe : Rcpp 0.7.7 |- http://tr.im/O1wO : highlight 0.1-5 `- http://tr.im/O1qJ : Rcpp 0.7.6 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to repeat the names?
Hello, That's not the problem here. The variables are read as factors. You can use the stringAsFactors argument of read.csv to turn this off: read.csv( 'city.csv', stringsAsFactors = FALSE ) and then you can proceed as you did. Romain On 02/10/2010 10:44 AM, Paul Hiemstra wrote: Hi, Take a look at rep(), specifically the each = parameter. cheers, Paul Madhavi Bhave wrote: Dear R helpers I have a city.csv file as given below. 'city.csv' city_name1 city_name2 New York City Buffallo So I define city_name = read.csv('city.csv') city1 = city_name$city_name1 city2 = city_name$city_name2 My problem is how do I repeat the names one after other say 10 times i.e. my output should be like New York City Buffallo New York City Buffallo New York City Buffallo New York City ... ... ... ... I have tried the following commands rep(c(city1,city2), 5) and I got the output something like this [1] 1 1 1 1 1 1 ... If I try rep((city1,city2), 5) Error: unexpected ',' in rep((city1, Please guide Regards MAdhavi -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/NrTG : Rcpp 0.7.5 |- http://tr.im/MPYc : RProtoBuf: protocol buffers for R `- http://tr.im/KfKn : Rcpp 0.7.2 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fast way to determine number of lines in a file
Hi, parser::nlines does it in C. Romain On 02/08/2010 03:16 PM, Hadley Wickham wrote: Hi all, Is there a fast way to determine the number of lines in a file? I'm looking for something like count.lines analogous to count.fields. Hadley -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/MPYc : RProtoBuf: protocol buffers for R |- http://tr.im/KfKn : Rcpp 0.7.2 `- http://tr.im/JOlc : External pointers with Rcpp __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fast way to determine number of lines in a file
On 02/08/2010 04:16 PM, Hadley Wickham wrote: parser::nlines does it in C. Looks promising, but I need something that uses connections because I'm working with big bzipped files. Hadley Ah... the lack of c-level api for connections again ;-) -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/MPYc : RProtoBuf: protocol buffers for R |- http://tr.im/KfKn : Rcpp 0.7.2 `- http://tr.im/JOlc : External pointers with Rcpp __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Number with fixed digit length - zero fill-up
Here is one way: sprintf( %08d, 10110 ) [1] 00010110 Romain On 02/01/2010 09:00 AM, Jägermeyr, Jonas wrote: Dear R-help members, I'm quite new to R and I apologize for my basic question, but I haven't been able to find a solution yet. I try to interpret vector entries as a binary code, but unfortunately every first digit which is zero disappears. So how can I set any number (e.g. x = 10110) to a 8-digit zero fill-up (x = 00010110) in order to address digit indices? Or other way round, how can I make the 'substr' function to count from the right hand side? Thank you. With kind regards, Jonas Jägermeyr Department of Geography Humboldt-University of Berlin jonas.jaegerm...@geo.hu-berlin.de -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/KfKn : Rcpp 0.7.2 |- http://tr.im/JOlc : External pointers with Rcpp `- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error with toString
On 01/26/2010 03:09 PM, anna wrote: Hello there, I want to create a string from strings and numbers, here is my code: str- name toString(20) Where did you get that syntax from ? You need to use paste. paste( name, 20 ) [1] name 20 but it returns me this error: Error in toString(20) : could not find function .jcall what did I do wrong? I couldn't find this error anywhere... .jcall is in rJava, but rJava never calls toString. Can you attach a bit more information as requested by the posting guide : http://www.r-project.org/posting-guide.html Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/KfKn : Rcpp 0.7.2 |- http://tr.im/JOlc : External pointers with Rcpp `- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] reading a string vector
On 01/26/2010 02:08 PM, bia.estat wrote: Hi, I need to read a string vector in R which is like this atgctctaatcgtcccaacaattatattactaccac, but R seems to understand it as a unique vector input when I read in like x- atgctctaatcgtcccaacaattatattactaccac. How do I unconcatenate it, so I can use each of the letters on my reading? Thanks, Beatriz See ?strsplit strsplit( x, )[[1]] Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/KfKn : Rcpp 0.7.2 |- http://tr.im/JOlc : External pointers with Rcpp `- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error with toString
On 01/26/2010 04:19 PM, anna wrote: Romain, I used the paste for numbers to as you told me and it worked. For the toString() function well I called it from the R console and that's what it returned me... Yes. I understood that the first time. and I asked you to provide more details about your session to help diagnose the problem better. I can figure out on my own that you typed it at the console. What I cannot figure out is details of your session. Please read the posting guide, follow it and come back with the details if you want someone to help. You might want to read An Introduction to R too, because R is nothing like vb. Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/KfKn : Rcpp 0.7.2 |- http://tr.im/JOlc : External pointers with Rcpp `- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Where can I get training for R-PLUS
On 01/25/2010 03:02 PM, jamy wrote: Hi friends, Does any one know ,where can I get free training for R-PLUS.If any one know please let me know. Thanks, James. http://lmgtfy.com/?q=R-plus+training -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/KfKn : Rcpp 0.7.2 |- http://tr.im/JOlc : External pointers with Rcpp `- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] header files for R packages
On 01/24/2010 04:37 AM, David Lubbers wrote: I have 6 or 7 nice constants (for example 1852 meters per nautical mile) I would like to have available to 4 or 5 functions in an R package. In C this would just be a header .h file and I would just include I am stuck trying to figure out how to create something like a C header file for an R package. Any ideas? Hi, If your package has a namespace, it is easy. If not, add one. Just create the constants in one of your R files within the package. that's it. If you don't export the constant, that is all you really need. Otherwise, you can lock the binding using lockBinding, but this is not full proof as one can still remove the variable and recreate it ... it just makes it harder to modify, but not impossible Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/KfKn : Rcpp 0.7.2 |- http://tr.im/JOlc : External pointers with Rcpp `- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] matrix to a C function
Christophe, That's another question for the R-devel mailing list. A few things however. Short answer : no it is not possible. I don't think x[i,j] is even syntactically valid in C or C++. I'd suggest you to give a go at the .Call interface that lets you manipulate R objects directly. So in your example with the .Call interface you'd only have to pass one argument and figure out the matrix dimensions internally with the C api of R. Something like this perhaps: SEXP pr( SEXP x ){ /* extract the dim attribute */ SEXP dim = getAttrib( x, R_DimSymbol ) ; int nrow = INTEGER(dim)[0]; int ncol = INTEGER(dim)[1]; /* extracting the pointer just once */ double * p = REAL(x) ; int i,j; for( i=0; inrow; i++){ for( j=0; jncol; j++){ Rprintf( %f , p[i+nrow*j] ) ; } Rprintf( \\n ) ; }; return R_NilValue ; /* NULL */ } You can use the regular print function (called PrintValue internally), which will nicely take care of aligning the columns properly, etc ... SEXP pr( SEXP x ){ PrintValue( x ) ; return( R_NilValue ) ; } Finally, you can use C++ through the Rcpp package and write something like this : SEXP pr( SEXP x){ RcppMatrixViewdouble m(x) ; int i,j; int nrow = m.rows() ; int ncol = m.cols() ; for( i=0; inrow; i++){ for( j=0; jncol; j++){ Rprintf( %f, m(i,j) ) ; } Rprintf( \\n ) ; } return R_NilValue ; } The indexing here is done with the round brackets here because it is just not valid to have more than one parameters passed to operator[] in C or C++. Romain On 01/23/2010 05:04 PM, Christophe Genolini wrote: Hi the list, Is there a way to give a matrix to a C function, and then to use it as a matrix ? I write a function to print a matrix, but I use it as a vector : 1. void printMatrix(double *mTraj,int *nbCol, int *nbLigne){ 2. int i=0,j=0; 3. for(i=0 ; i *nbLigne ; i++){ 4. for(j=0 ; j *nbCol ; j++){ 5. Rprintf( %f,mTraj[i * *nbCol + j]); 6. } 7. Rprintf(\n); 8. } 9. } I would like to use it as a matrix (line 5 changes) : 1. void printMatrix(double *mTraj,int *nbCol, int *nbLigne){ 2. int i=0,j=0; 3. for(i=0 ; i *nbLigne ; i++){ 4. for(j=0 ; j *nbCol ; j++){ 5. Rprintf( %f,mTraj[i,j]); 6. } 7. Rprintf(\n); 8. } 9. } It does not work, but is there an solution close to this ? Thanks. Christophe -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/KfKn : Rcpp 0.7.2 |- http://tr.im/JOlc : External pointers with Rcpp `- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Optimizing C code
Bonjour Christophe, NA and NaN are different things... Actually this is tricky because NA is implemented as a special kind of NaN : See this extract of R_ext/Arith.h : int R_IsNA(double); /* True for R's NA only */ int R_IsNaN(double);/* True for special NaN, *not* for NA */ int R_finite(double); /* True if none of NA, NaN, +/-Inf */ #define ISNA(x)R_IsNA(x) /* ISNAN(): True for *both* NA and NaN. NOTE: some systems do not return 1 for TRUE. Also note that C++ math headers specifically undefine isnan if it is a macro (it is on OS X and in C99), hence the workaround. This code also appears in Rmath.h */ #ifdef __cplusplus int R_isnancpp(double); /* in arithmetic.c */ # define ISNAN(x) R_isnancpp(x) #else # define ISNAN(x) (isnan(x)!=0) #endif Romain PS: the question would be more appropriate in R-devel. On 01/22/2010 11:14 AM, Christophe Genolini wrote: Hi the list, I need to write some efficient distances function, so I read the code for the Euclidean distance. I do not understand the purpose of the line 11 : if x[i] and y[i] are not NA (line 9), can dev be NA ? Christophe #define both_FINITE(a,b) (R_FINITE(a) R_FINITE(b)) #define both_non_NA(a,b) (!ISNAN(a) !ISNAN(b)) 1. static double R_euclidean2(double *x, double *y, int taille) 2. { 3. double dev, dist; 4. int count, i; 5. 6. count= 0; 7. dist = 0; 8. for(i = 0 ; i taille ; i++) { 9. if(both_non_NA(x[i], y[i])) { 10. dev = (x[i] - y[i]); 11. if(!ISNAN(dev)) { 12. dist += dev * dev; 13. count++; 14. } 15. } 16. } 17. if(count == 0)return NA_REAL; 18. if(count != taille) dist /= ((double)count/taille); 19. return sqrt(dist); 20.} -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/KfKn : Rcpp 0.7.2 |- http://tr.im/JOlc : External pointers with Rcpp `- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Working with text data/text operators
On 01/19/2010 01:22 PM, mihai.mira...@bafin.de wrote: Hello, Could someone tell me, how can I select from a dataframe only those columns whose names contain a certain text? For example, if the column names are Bond1.Creditclass,Bond1.Price,Bond2.Creditclass,Bond2.Price, how do I select only the columns corresponding to Bond1? Thanks a lot, Mihai You can do things like : dataset[ , grepl( ^Bond1, names( dataset ) ) ] dataset[ , substr( names( dataset ), 1, 5 ) == Bond1 ] Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/KfKn : Rcpp 0.7.2 |- http://tr.im/JOlc : External pointers with Rcpp `- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error: object of type 'closure' is not subsettable
On 01/17/2010 09:00 PM, Rolf Turner wrote: I thought it would be possible to make rep() work for functions by writing a method for the function class. I tried: rep.function - function(x,...) { times - as.list(...)[[1]] rslt - vector(list,times) rslt[1:times] - list(x) rslt } But then doing rep(sin,2) still gave an error --- Error: object of type 'builtin' is not subsettable Note the difference: ``builtin'' rather than ``closure''. I then noticed that there is no generic function for rep, although there are ***methods*** for rep. I don't understand this at all! So I did: rep.default - rep rep - function(x,...){UseMethod(rep)} Having taken these steps, rep(sin,2) worked as expected. But why doesn't rep() have a generic form? And how can there be methods ***without*** a generic? Can anyone explain the issues to me, preferably in terms that are comprehensible to the human mind (which is what I'm equipped with)? rep is an internal generic, so the dispatch happens internally (in the c code). Here is the relevant C code fragment : SEXP attribute_hidden do_rep(SEXP call, SEXP op, SEXP args, SEXP rho) { SEXP ans, x, ap, times = R_NilValue /* -Wall */, ind; int i, lx, len = NA_INTEGER, each = 1, nt, nprotect = 4; if (DispatchOrEval(call, op, rep, args, rho, ans, 0, 0)) return(ans); ... } Romain cheers, Rolf Turner On 14/01/2010, at 2:24 PM, Gabor Grothendieck wrote: See ?rep where it says that the argument must be a vector. Try rep(list(sin), 3) On Wed, Jan 13, 2010 at 8:11 PM, Matthew Walker matthew.walke...@ulaval.ca wrote: Hi everyone, Would somebody please explain (or point me to a reference that explains) the following error: Error: object of type 'closure' is not subsettable I was trying to use rep() to replicate a function: example_function - function() { return(TRUE) } rep(example_function, 3) Error: object of type 'closure' is not subsettable But I just cannot understand this error. I can combine functions using c without any problems: c(example_function, example_function) [[1]] function () { return(TRUE) } [[2]] function () { return(TRUE) } What am I doing wrong when I use rep()? Thanks in advance, Matthew Walker -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/KfKn : Rcpp 0.7.2 |- http://tr.im/JOlc : External pointers with Rcpp `- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Logical function
Here's one way : ds - data.frame( st = runif(100), s0=runif(100), s1=runif(100),s2=runif(100),mp=runif(100)) ds - within( ds, { n1 - 1*( st0.38 ) n2 - numeric( length( st ) ) n2[ is.na(st) | st = 0.38 ] - .25 n2[ s0 == mp ] - .25 n2[ s2 == mp ] - .5 n2[ mp == 1 ] - .75 } ) See ?within for why/how this works. Romain On 01/14/2010 11:10 AM, Olivier Deckmyn wrote: Dear all, I'm learning R, with a classical programming background. Some hours were necessary for me to programm the vector way. Here is my dataset : ds- data.frame( st=runif(100), st=runif(100),s1=runif(100),mp=runif(100)) I need to generate 2 new variables. First was easy : ds$n1- (ds$st0.38)*1 Second involve a if statement. Here is the python way of expressing what I need : nash- function(st,s0,s1,mp){ if (is.na(st) | (st=0.38)){ return(0.25) } if (s0 == mp){ return(0.25) } if (s1 == mp){ return(0.5) } if (mp == 1){ return(0.75) } } I would like to do something like : ds$n2- nash(ds) I mean I would like to add a new variable n2, whose value depends on the value of other variables - row per row. I played with a for loop (don't flame :p), with apply functions and derivatives, with a logical set, etc Can you help me find the R way, please ? Cheers, -- Olivier Deckmyn | oliv...@deckmyn.org | 06 73 40 89 88 -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/KfKn : Rcpp 0.7.2 |- http://tr.im/JOlc : External pointers with Rcpp `- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Better way than an ifelse statement?
Or this ; example$X3 - c(-3, -1, 1, 3)[ example$X2 ] Romain On 01/14/2010 11:55 AM, Henrique Dallazuanna wrote: Try this: example$X3- sapply(example$X2, switch, -3, -1, 1, 3) On Thu, Jan 14, 2010 at 5:05 AM, Joshua Wileyjwiley.ps...@gmail.com wrote: Hello All, I am trying to create a column of weights based off of factor levels from another column. I am using the weights to calculate L scores. Here is an example where the first column are scores, the second is my factor and the third I want to be a column of weights. I can do what I want with an ifelse statement (see below), but I am wondering if anyone knows of a cleaner way to do this? example- data.frame(cbind(rnorm(4), rep(1:4, 1), c(0))) example$X3- ifelse(example$X2==1, -3, ( ifelse(example$X2==2, -1, ( ifelse(example$X2==3, 1, ( ifelse(example$X2==4, 3, NA))) ## this seems sloppy to me example X1 X2 X3 1 1.75308880 1 -3 2 -0.49273616 2 -1 3 -0.12446648 3 1 4 -0.06417217 4 3 Thanks for your help, Joshua -- Joshua Wiley Senior in Psychology University of California, Riverside http://www.joshuawiley.com/ -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/KfKn : Rcpp 0.7.2 |- http://tr.im/JOlc : External pointers with Rcpp `- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] question on 'within' and 'parse' commands
Hello, parse just parse the text into an expression. parse(text=a-a*10; b-2:6) expression(a-a*10, b-2:6) attr(,srcfile) text If you want to evaluate the expression, you need to call eval y - within(x, eval(parse(text=a-a*10; b-2:6))) y a b 1 10 2 2 20 3 3 30 4 4 40 5 5 50 6 Or you can just do this : y - within(x, { a-a*10; b-2:6 } ) y a b 1 10 2 2 20 3 3 30 4 4 40 5 5 50 6 Romain On 01/07/2010 09:08 AM, N Klepeis wrote: Hi, Why can't I pass an expression to `within' by way of textual input to the 'parse' function? e.g., x - data.frame(a=1:5,b=LETTERS[1:5]) x a b 1 1 A 2 2 B 3 3 C 4 4 D 5 5 E within(x, parse(text=a-a*10; b-2:6)) a b 1 1 A 2 2 B 3 3 C 4 4 D 5 5 E within(x, parse(text=a-a*10; b-2:6)[[1]]) a b 1 1 A 2 2 B 3 3 C 4 4 D 5 5 E This would be very useful to allow for arbitrary evaluation of multi-line commands at runtime. Of course, I can edit the 'within.data.frame' function as follows, but isn't there some way to make 'within' more generally like the 'eval' command? alternative: within.data.frame - function (data, textCMD, ...) { parent - parent.frame() e - evalq(environment(), data, parent) eval(parse(text=textCMD), e) # used to be eval(substitute(expr), e) l - as.list(e) l - l[!sapply(l, is.null)] nD - length(del - setdiff(names(data), (nl - names(l data[nl] - l if (nD) data[del] - if (nD == 1) NULL else vector(list, nD) data } --Neil -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009 |- http://tr.im/IW9B : C++ exceptions at the R level `- http://tr.im/IlMh : CPP package: exposing C++ objects __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] issue with using rm: cannot generate on-the-fly list
The list argument of rm is supposed to be a character vector, as indicated in ?rm. not a list. You can do something like this: rm( list = Filter( exists, c(rv1,rv2, rv3, rv4) ) ) or, considering rm only warns when you attempt to remove objects, you could: suppressWarnings( rm( list = c(rv1,rv2, rv3, rv4) ) ) Romain On 12/17/2009 11:33 AM, Cormac Long wrote: Hello, I have the following problem when trying to use rm: In a top level script file I have a loop iterating over some index. The loop is not contained within a function, so the scope of variables declared in the loop is global. Within this loop I generate several variables which should be removed at the end of each iteration. To do this, I wrote a function to clean up the workspace. An example is included here: cleanUpWorkspace-function() { #Remove key data sructures, if they have been declared: delList-list() for(varname in c(rv1,rv2, rv3, rv4)) { if(exists(varname)) { delList-append(delList, varname) } } if(length(delList)0) { rm(list=delList, pos=-1) #rm(list=delList, envir=parent.env(environment())) #rm(list=delList, envir=globalenv()) } } Unfortunately, this fails to work - it aborts with the following error: Error in rm(list = delList, pos = -1) : invalid first argument if I use rm(list=delList, pos=-1) Or with the following error: Error in rm(list = delList, evir = parent.env(environment())) : ... must contain names or character strings if I use rm(list=delList, envir=parent.env(environment())) or rm(list=delList, envir=globalenv()) I get the same errors if I bypass rm entirely and use .Internal(remove(delList, globalenv(),FALSE)). I am using R version 2.10.0 running on a windows 7 box. I want to declare the clean-up within a function for design purposes. The full project is spread over several files and I am trying to keep the main loop as simple as possible. Sincerly, Cormac Long. -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/HlX9 : new package : bibtex |- http://tr.im/Gq7i : ohloh `- http://tr.im/FtUu : new package : highlight __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to find the significant digits of a number?
On 12/16/2009 10:26 AM, Xiang Wu wrote: Is there a function in R that could find the significant digit of a specific number? Such as for 3.1415, return '5'? Thanks in advance. Not sure to understand what you mean, but you can have a look at ?signif Something like this perhaps: foo - function( x, y) abs( round( 10^y * (x - signif(x,y) ) ) ) foo( 3.1415, 4 ) [1] 5 -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/HlX9 : new package : bibtex |- http://tr.im/Gq7i : ohloh `- http://tr.im/FtUu : new package : highlight __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating bibtex file of all installed packages?
On 12/16/2009 08:32 AM, Achim Zeileis wrote: On Tue, 15 Dec 2009, Michael Friendly wrote: Achim and others: Achim's solution could be directly usable if it also added a BibTeX key, perhaps just the name of the package to the '@Manual{,' initial line of each. I wrapped the previous suggestions in a function, and played around with the components, but can't quite see how to account for the failed citation calls. Can anyone take the next step? I had also thought about this after sending my previous solution, so here is an update Michael's version of the function (renamed to the name of the default file). Apart from some smaller touch-ups this has the following changes: - Instead of taking the unique() bibs, I now use the unique() pkgs. (In principle, packages with the same name could be installed in different libraries, potentially containing different citations. But I thought it would be overkill to check for that.) - Citation keys are simply pkgname if there is only a single BibTeX item, and pkgname1 to pkgnameN if there are N BibTeX items. (This does not assure that citation keys are unique, though. If there is a package foo with 2 citation entries and another package foo2 with only a single entry, these could be confused. A workaround would be to use pkgname1 instead of pkgname as the citation key even if there is a single citation only. But I thought that would be less intuitive.) Rpackages.bib - function(file = Rpackages.bib, verbose = TRUE) { ## installed packages pkgs - unique(installed.packages()[,1]) bibs - lapply(pkgs, function(x) try(toBibtex(citation(x n.installed - length(bibs) ## omit failed citation calls ok - !(sapply(bibs, class) == try-error) pkgs - pkgs[ok] bibs - bibs[ok] n.converted - sum(ok) ## unify to list of Bibtex bibs - lapply(bibs, function(x) if(inherits(x, Bibtex)) list(x) else x) ## add bibtex keys to each entry pkgs - lapply(seq_along(pkgs), function(i) if(length(bibs[[i]]) 1) paste(pkgs[i], 1:length(bibs[[i]]), sep = ) else pkgs[i]) pkgs - do.call(c, pkgs) bibs - do.call(c, bibs) for(i in seq_along(pkgs)) bibs[[i]][1] - gsub({,, paste({, pkgs[i], ,, sep = ), bibs[[i]][1], fixed = TRUE) ## write everything to a single .bib file writeLines(do.call(c, lapply(bibs, as.character)), file) if(verbose) cat(Converted, n.converted, of, n.installed, package citations to BibTeX, \nResults written to file, file, \n) ## return Bibtex items invisibly invisible(bibs) } Best, Z And you can read it back into R with package bibtex: require( bibtex ) entries - read.bib( Rpackages.bib ) but then although the key is read, it is not displayed, because of utils:::toBibtex.citation: entries[[1]] A BibTeX entry for LaTeX users is @Manual{, title = {ant: Version of ant specific to R}, author = {Romain Francois}, year = {2009}, note = {R package version 0.0-10}, } str( entries[[1]] ) List of 4 $ title : chr ant: Version of ant specific to R $ author:List of 1 ..$ :List of 2 .. ..$ name : Named chr [1:3] Romain Francois .. .. ..- attr(*, names)= chr [1:3] first middle last .. ..$ email: NULL .. ..- attr(*, class)= chr person ..- attr(*, class)= chr personList $ year : chr 2009 $ note : chr R package version 0.0-10 - attr(*, class)= chr citation - attr(*, srcref)=Class 'srcref' atomic [1:6] 1 1 6 1 1 1 .. ..- attr(*, srcfile)=Class 'srcfile' environment: 0x8ed067c - attr(*, entry)= chr Manual - attr(*, key)= chr ant Should I submit some patch to allow printing of the key when there is a key attribute. Maybe the key could also be used for character based indexing of citationList objects. Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/HlX9 : new package : bibtex |- http://tr.im/Gq7i : ohloh `- http://tr.im/FtUu : new package : highlight __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Combinations
On 12/14/2009 10:50 AM, baptiste auguie wrote: Hi, Try this, apply(expand.grid(letters[1:3], letters[24:26]), 1, paste,collapse=) [1] ax bx cx ay by cy az bz cz This will be faster, as it takes advantage of the vectorized paste: cpaste - function(...) paste(..., sep = ) do.call( cpaste, expand.grid(letters[1:3], letters[24:26]) ) Romain system.time( do.call( cpaste, expand.grid(letters[1:26], letters[1:26]) ) ) user system elapsed 0.002 0.000 0.002 system.time( apply(expand.grid(letters[1:26], letters[1:26]), 1, paste,collapse=) ) user system elapsed 0.015 0.000 0.018 Does not make too much difference on the OP example: glue - function( ... ){ cpaste - function(...) paste(..., sep = ) do.call( cpaste, do.call( expand.grid, list(...) ) ) } GLUE - function(...){ apply( do.call( expand.grid, list(...) ), 1, paste, collapse = ) } system.time( glue( A = c(a,b,c), B = c(x, y, z), C = c(l, m, n), D = c(p,q,r), E = c(s, t, u) ) ) user system elapsed 0.002 0.000 0.002 system.time( GLUE( A = c(a,b,c), B = c(x, y, z), C = c(l, m, n), D = c(p,q,r), E = c(s, t, u) ) ) user system elapsed 0.008 0.000 0.008 ?expand.grid HTH, baptiste 2009/12/14 Amelia Livingtonamelia_living...@yahoo.com: Dear R helpers, I am working on the scenario analysis pertaining to various interest rates. In this connection I need to form the various combinations as under : Suppose I have two sets A = (a, b, c) and B = (x,y,z) Then I can easily form the cominations as (ax, ay, az, bx, by, bz, cx, cy, cz) However, if I have say 5 variables, then total no of possible combinations will be 3^5 = 243. Thus, A = (a,b,c), B = (x, y, z), C = (l, m, n), D = (p,q,r), E = (s, t, u). Then may be my possble combination will start as (a, x, l, p, s), then next combination may be (a, x, l, p, u) and so on. The last combination (243rd in this case) may be (c, z, n, r, u) or something like this. In R, is there any way to list all these 3^5 = 243 combinations? Amelia -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/HlX9 : new package : bibtex |- http://tr.im/Gq7i : ohloh `- http://tr.im/FtUu : new package : highlight __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Why doesnot Rscript work ?
Hi, Rscript is meant for non-interactive use, so the default device is not the same as when you run R. If you really want a window, open it yourself by calling the appropriate function (X11, windows, ... ) or reset the device option to whichever device you want to use, but it will disappear at the end of the script, so not very interesting. You probably should open a png device or something and then write the grap there. See ?png, ?pdf, ?X11, ?options, ?Rscript Romain On 12/14/2009 10:59 AM, z_axis wrote: %cat stock.R #! /usr/local/bin/Rscript args- commandArgs(TRUE) args x- read.csv(000301.csv) matplot(x[,1],x[,-1],type=l) #q(save=no) %Rscript stock.R 000301.csv [1] 000301.csv matplot doesnot draw anything(no drawing window). Howeve, in R, source works great! source(stock.R) Sincerely! -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/HlX9 : new package : bibtex |- http://tr.im/Gq7i : ohloh `- http://tr.im/FtUu : new package : highlight __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Printing to PDF in for
See the onefile and file arguments of ?pdf and then do something like this : pdf( file = plot-%03d.pdf, onefile = FALSE, width = 9.25, height = 9.25, family=Helvetica,pointsize=8,bg=white ) Romain On 12/14/2009 12:09 PM, Trafim Vanishek wrote: Hi everybody, I would like to ask if it is possible using pdf function or some other to print plots in cycle such that every new plot is on new page. like this pdf(file=D:/Plot.pdf,width = 9.25,height=9.25, family=Helvetica,pointsize=8,bg=white) for (i in 1:10){ x- seq(1,40,1) y- 2*x+1+5*rnorm(length(x)) hist(y,freq = FALSE) plot(density(y)) } dev.off( ) but the problem is that I have a lot of other code in the cycle which I don't want to be printed in PDF. Thanks a lot for the help -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/HlX9 : new package : bibtex |- http://tr.im/Gq7i : ohloh `- http://tr.im/FtUu : new package : highlight __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to use Rengine instance to parse R script String
On 12/14/2009 01:35 PM, Gray Calhoun wrote: Hi hobartlul, The R-devel mailing list is more appropriate for this sort of question. Slightly, but the one mailing list where the question actually fits is this one : http://mailman.rz.uni-augsburg.de/mailman/listinfo/stats-rosuda-devel You'll probably get the best response there if you include your own code (that I assume is not running correctly) and ask about specific errors you're getting please ---I don't know that anyone has their own small, self contained example that it would be easy for them to send you. Best, Gray On Sun, Dec 13, 2009 at 4:08 PM, hobartlulhobart...@gmail.com wrote: Hello everyone I am currently developing a web based R script editor. My idea is to pass the R script command as a string into the backend , then use the Rengine instance to parse the R script command and get the resutls. Do anyone know how to use Rengine instance to parse a R script String? if so, could you give me a small example (in Java)? i really appreciate. -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/HlX9 : new package : bibtex |- http://tr.im/Gq7i : ohloh `- http://tr.im/FtUu : new package : highlight __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Literature analysis
Hello, Sorry to arrive late on this. Did you try the recently uploaded bibtex package. It reads a bibtex file into an R list (of class citationList). So for example : if your posted example lives in biblio.bib for example, you can read it like this : bib - read.bib( biblio.bib ) sapply( bib[[1]], function(item) item$title ) [1] Adsorption and Diffusion of VOsup2+/sup and\nVOsub2/sub sup+/sup\n\tacross Cation Membrane for All-Vanadium Redox Flow Battery [2] Modification of Daramic, microporous separator, for redox\nflow battery\n\tapplications Romain On 12/11/2009 03:41 PM, Schwan wrote: They are in Bibtex For example: @ARTICLE{adsdifvanadiumcationexchange, author = {Jin-qing Chen and Bao-guo Wang and Ji-chu Yang}, title = {Adsorption and Diffusion of VOsup2+/sup and VOsub2/sub sup+/sup across Cation Membrane for All-Vanadium Redox Flow Battery}, journal = {Solvent Extraction and Ion Exchange}, year = {2009}, volume = {27}, pages = {312--327}, number = {2}, abstract = {A method based on a selectivity coefficient and the Nernst-Planck equation is proposed to determine diffusion coefficients of vanadium ions across a cation exchange membrane in VOsup2+/sup/Hsup+/sup and VOsub2/sub sup+/sup/Hsup+/sup systems. This simplified method can be applied to high concentrations of vanadium ions. Three cation exchange membranes were studied. The logarithmic value of the selectivity coefficient was linearly dependent on the molar fraction of vanadium ions in solution. The diffusion coefficient of vanadium ions decreased with decreasing water content. The membrane with the lowest diffusion coefficient was selected as a battery separator and showed the lowest capacity loss of the studied membranes.}, issn = {0736-6299}, publisher = {Taylor \ Francis}, url = {http://www.informaworld.com/10.1080/07366290802674614} } @ARTICLE{Chieng1992, author = {Chieng, S.C. and Kazacos, M. and Skyllas-Kazacos, M.}, title = {Modification of Daramic, microporous separator, for redox flow battery applications}, journal = {Journal of Membrane Science}, year = {1992}, volume = {75}, pages = {81--91}, number = {1-2}, month = dec, issn = {0376-7388}, keywords = {Daramic, microporous separator, redox flow cell and battery}, owner = {schwan}, timestamp = {2009.11.30}, url = {http://www.sciencedirect.com/science/article/B6TGK-43S71CR-7K/2/06f90d391c0eff0ff5df3f282ad5fe28} } On Fri, 2009-12-11 at 15:37 +0100, Gustaf Rydevik wrote: On Fri, Dec 11, 2009 at 3:04 PM, Schwans.s.hosse...@utwente.nl wrote: Thanks, but how should I put the citation inside a data frame? data.frame(first txt file, second txt file...) plot (what should I insert here) type=p And how should I load the txt files anyway inside the frame? Can you give an example of a couple of text files? Are they in a standardised format (i.e. bibTEX or similar)? /Gustaf -- Gustaf Rydevik, M.Sci. tel: +46(0)703 051 451 address:Essingetorget 40,112 66 Stockholm, SE skype:gustaf_rydevik -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/HlX9 : new package : bibtex |- http://tr.im/Gq7i : ohloh `- http://tr.im/FtUu : new package : highlight __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] code for [[.data.frame
On 12/13/2009 02:42 PM, Guillaume Yziquel wrote: baptiste auguie a écrit : `[[.data.frame` Note that this will only be the source code if you have options keep.source and keep.source.pkgs set to TRUE, and the environment variable R_KEEP_PKG_SOURCE equal to yes. Otherwise you see the code parsed and deparsed, which loses comments and formatting. `[[.data.frame` function(x, ..., exact=TRUE) { ## use in-line functions to refer to the 1st and 2nd ... arguments ## explicitly. Also will check for wrong number or empty args na - nargs() - !missing(exact) if(!all(names(sys.call()) %in% c(, exact))) warning(named arguments other than 'exact' are discouraged) if(na 3L) (function(x, i, exact) if(is.matrix(i)) as.matrix(x)[[i]] else .subset2(x, i, exact=exact))(x, ..., exact=exact) else { col - .subset2(x, ..2, exact=exact) i - if(is.character(..1)) pmatch(..1, row.names(x), duplicates.ok = TRUE) else ..1 .subset2(col, i, exact=exact) } } environment: namespace:base writeLines( deparse( `[[.data.frame` ) ) function (x, ..., exact = TRUE) { na - nargs() - (!missing(exact)) if (!all(names(sys.call()) %in% c(, exact))) warning(named arguments other than 'exact' are discouraged) if (na 3L) (function(x, i, exact) if (is.matrix(i)) as.matrix(x)[[i]] else .subset2(x, i, exact = exact))(x, ..., exact = exact) else { col - .subset2(x, ..2, exact = exact) i - if (is.character(..1)) pmatch(..1, row.names(x), duplicates.ok = TRUE) else ..1 .subset2(col, i, exact = exact) } } Romain and more generally see Rnews Volume 6/4, October 2006 Accessing the Sources. HTH, baptiste Thank you so much. Indeed, I've been able to look at the source code of the function from the source code of R. But I was quite keen on knowing how to do this from the toploop. Thanks a lot. -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/HlX9 : new package : bibtex |- http://tr.im/Gq7i : ohloh `- http://tr.im/FtUu : new package : highlight __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to resolve include Rcpp.h problems?
Hi, The file lives in the lib directory of the installed package Rcpp. Rscript -e cat(system.file( 'lib', 'Rcpp.h', package = 'Rcpp' )) The maintainer of Rcpp (cc'ed, just in case) will tell you more tricks. Note that Rcpp has its own mailing list. https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel where questions like this might be more appropriate. Romain On 12/13/2009 09:56 AM, Amine Jallouli wrote: Hi, I am Linux Ubuntu 9.04 user. I'm using R-2.6. Actually, I am developing R package for reading/writing 3D images. I needed to use the R package Rcpp in order to make profit of available C/C++ codes. My problem is that my C code is not able to include the Rcpp.h In fact, when I run this command R CMD build rply, I got the following error message in the file /home/amine/R/r-eclipse/rply.Rcheck/00install.out: * Installing *source* package 'rply' ... ** libs gcc -std=gnu99 -I/usr/share/R/include -fpic -g -O2 -c Call_interface.c -o Call_interface.o gcc -std=gnu99 -I/usr/share/R/include -fpic -g -O2 -c C_interface.c -o C_interface.o gcc -std=gnu99 -I/usr/share/R/include -fpic -g -O2 -c fifrt.c -o fifrt.o g++ -I/usr/share/R/include -fpic -g -O2 -c RCPP_test.cpp -o RCPP_test.o RCPP_test.cpp:1:18: erreur: Rcpp.h : No such file or directory RCPP_test.cpp: In function ‘SEXPREC* readRIntVec(SEXPREC*)’: RCPP_test.cpp:14: erreur: ‘RcppVector’ was not declared in this scope RCPP_test.cpp:14: erreur: expected primary-expression before ‘int’ RCPP_test.cpp:14: erreur: expected `;' before ‘int’ make: *** [RCPP_test.o] Erreur 1 ERROR: compilation failed for package 'rply' ** Removing '/home/amine/R/r-eclipse/rply.Rcheck/rply' It is evident that I will this error since the file Rcpp.h is not in this directory /usr/share/R/include . I tried to solve this include problem by copying the Rcpp.h to /usr/share/R/include. But, it was not successful and I the following error message. Error in dyn.load(file, DLLpath = DLLpath, ...) : Unable to load shared library '/home/amine/R/r-eclipse/rply.Rcheck/rply/libs/rply.so': /home/amine/R/r-eclipse/rply.Rcheck/rply/libs/rply.so: undefined symbol: _ZN10RcppVectorIiEC1EP7SEXPREC Error in library(rply) : .First.lib has failed for 'rply' Execution stopped It looks like this package has a loading problem: see the messages for details. Resulting this last error seems to be also logical. In fact, I think the file libRcpp.so is need for the compilation of my code. Please notice that the package Rcpp is installed in the following directory: /usr/lib/R/site-library/Rcpp Thank you for giving an idea for solving this problem. -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/HlX9 : new package : bibtex |- http://tr.im/Gq7i : ohloh `- http://tr.im/FtUu : new package : highlight __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating bibtex file of all installed packages?
On 12/11/2009 08:41 AM, Achim Zeileis wrote: On Fri, 11 Dec 2009, Rainer M Krug wrote: Hi is there an easy and fast way, to generate a BibTeX file of all installed / loaded packages and R? I know about toBibtex(citation()) to extract the BibTeX for a single package, but how can I generate a file containg citations for all installed / loaded packages? I don't think that there is a way other than calling citation() for each of the installed.packages(). You could do something like this: ## try to get BibTeX for each of the installed packages b - lapply(installed.packages()[,1], function(x) try(toBibtex(citation(x ## omit failed citation calls b - b[-which(sapply(b, class) == try-error)] I would use logical indexing instead of which because if none actually fail, you end up indexing by integer(0) so b is empty. b - b[!(sapply(b, class) == try-error)] ## unify to list of Bibtex b - lapply(b, function(x) if(inherits(x, Bibtex)) list(x) else x) ## list of unique entries b - unique(do.call(c, b)) ## write everything to a single .bib file writeLines(do.call(c, lapply(b, as.character)), Rpackages.bib) hth, Z If you then want to do the reversed operation, read a bibtex file into a citationList object, you can use the unreleased(*) package bibtex. install.packages(bibtex, repos=http://R-Forge.R-project.org;) require( bibtex ) Loading required package: bibtex bib - read.bib( Rpackages.bib ) There were 50 or more warnings (use warnings() to see the first 50) (*) because I have been lazy The warnings are all about the lack of keys in the entries cooked by toBibtex. no big deal. Romain Cheers, Rainer -- NEW GERMAN FAX NUMBER!!! Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Cell: +27 - (0)83 9479 042 Fax: +27 - (0)86 516 2782 Fax: +49 - (0)321 2125 2244 email: rai...@krugs.de Skype: RMkrug Google: r.m.k...@gmail.com [[alternative HTML version deleted]] -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/Gq7i : ohloh |- http://tr.im/FtUu : new package : highlight `- http://tr.im/EAD5 : LondonR slides __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] copyING directories and files
What about this as a start : dir.copy - function( source = getwd(), target ){ files - list.files( source, recursive = TRUE ) dirs - unique( gsub( /[^/]+$, , files[grepl(/, files)] ) ) if( !file.exists( target ) ){ dir.create( target ) } for( d in dirs){ dir.create( file.path( target, d) , recursive = TRUE ) } for( f in files ){ file.copy( file.path(source, f) , file.path( target, f ) ) } invisible(NULL) } # what I am copying : system( tree ) . └── bar ├── blabla.txt ├── bla.txt └── foobar └── blabla.txt 2 directories, 3 files dir.copy( getwd(), /tmp/target ) system( tree /tmp/target ) /tmp/target └── bar ├── blabla.txt ├── bla.txt └── foobar └── blabla.txt 2 directories, 3 files Romain On 12/11/2009 11:18 AM, Uwe Ligges wrote: I'd use a shell() command to call xcopy or robocopy, or cp given you have some unix tools installed. Uwe Ligges Paul Evans wrote: Hi, I am using the windows version of R. I wanted to copy a directory (containing several files) to another directory. Is there any command in R that will let me do this (something like the 'cp' command in UNIX)? I have looked at 'file.copy', but as the name implies I think it only copies one file at a time. thanks! -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/Gq7i : ohloh |- http://tr.im/FtUu : new package : highlight `- http://tr.im/EAD5 : LondonR slides __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Brew Package
Hi, Did you read the documentation that comes with the package. require( brew ) ?brew Romain On 12/08/2009 10:40 AM, Shreyasee wrote: Dear R users, I want more information about the package Brew. The example which is given here ( http://learnr.wordpress.com/2009/09/09/brew-creating-repetitive-reports/) is really complex to understand. Are there any simple examples through which I can learn about the Brew package? Thanks in advance, Shreyasee -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/Gq7i : ohloh |- http://tr.im/FtUu : new package : highlight `- http://tr.im/EAD5 : LondonR slides __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Brew Package
Hi, Maybe this would suit you (from the help page) file.show( system.file(catprint.brew,package=brew) ) file.show( system.file(brew-test-1.brew,package=brew) ) file.show( system.file(brew-test-2.brew,package=brew) ) brew syntax is quite simple, once you read the points 1:5 from the details section of ?brew, you know all you need to know. Romain On 12/08/2009 10:59 AM, Shreyasee wrote: Hi Romain, I read that but it seems to be too vague. Is there any detailed explanation available with simple examples? Thanks, Shreyasee On Tue, Dec 8, 2009 at 5:55 PM, Romain Francois romain.franc...@dbmail.com mailto:romain.franc...@dbmail.com wrote: Hi, Did you read the documentation that comes with the package. require( brew ) ?brew Romain On 12/08/2009 10:40 AM, Shreyasee wrote: Dear R users, I want more information about the package Brew. The example which is given here ( http://learnr.wordpress.com/2009/09/09/brew-creating-repetitive-reports/) is really complex to understand. Are there any simple examples through which I can learn about the Brew package? Thanks in advance, Shreyasee -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/Gq7i : ohloh |- http://tr.im/FtUu : new package : highlight `- http://tr.im/EAD5 : LondonR slides __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.