Re: [Rd] build time dependency
On 09/29/2009 04:36 AM, Seth Falcon wrote: On Mon, Sep 28, 2009 at 11:25 AM, Romain Francois wrote: Hi Uwe, I think you are supposed to do this kind of sequence: R CMD roxygen yourRoxygenablePackage R CMD build yourRoxygenablePackage_roxygen ... but I don't like this because what you upload to cran is not the actual source but somethingalready pre-processed. (This also applies to packages shipping java code, most people just compile the java code on their machine and only supply a jar of compiled code, but that's another story I suppose ...) I'd prefer the roxygenation to be part of the standard build/INSTALL system, so my plan is to write configure and configure.win which would call roxygenize to generate Rd. I can appreciate the desire to make the "true" sources available. At the same time, I think one should very carefully consider the expense of external dependencies on a package. One could view doc generation along the same lines as configure script generation -- a compilation step that can be done once instead of by all those who install and as a result reduce the depencency burden of those wanting to install the package. Configure scripts are almost universally included pre-built in distribution source packages so that users do not need to have the right version of autoconf/automake. The kind of configure[.win] scripts I am using are very simplistic and do not come from autoconf, etc ... something like this to compile the java source code using the ant package : #!/bin/bash cd inst/java_src "${R_HOME}/bin/Rscript" -e "ant::ant()" In other words, are you sure you want to require folks to install roxygen (or whatever) in order to install your package? Making it easy to do so is great, but in general if you can find a way to reduce dependencies and have your package work, that is better. :-) That is exactly what I am trying to do here, those who build the package are not necessarily the same as those who install it, so installation would not depend on roxygen. And Uwe is very right that what I am looking for is indeed __build__ time rather than __install__ time. + seth -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/ztCu : RGG #158:161: examples of package IDPmisc |- http://tr.im/yw8E : New R package : sos `- http://tr.im/y8y0 : search the graph gallery from R __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Downloading R-2.10.0
Duncan is travelling and may not yet have updated his scripts to make alpha versions available (rather than R-devel), please be patient. Best, Uwe Ligges Gabor Grothendieck wrote: For Windows, this page http://cran.r-project.org/bin/windows/base/ gives a link to download - R 2.9.2 - r-patched (R 2.9.2 patched) - old releases and - r-devel (R 2.11.0) but there is no obvious link to R 2.10.0. From where do we download that? __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] build time dependency
Romain Francois wrote: On 09/29/2009 04:36 AM, Seth Falcon wrote: On Mon, Sep 28, 2009 at 11:25 AM, Romain Francois wrote: Hi Uwe, I think you are supposed to do this kind of sequence: R CMD roxygen yourRoxygenablePackage R CMD build yourRoxygenablePackage_roxygen ... but I don't like this because what you upload to cran is not the actual source but somethingalready pre-processed. (This also applies to packages shipping java code, most people just compile the java code on their machine and only supply a jar of compiled code, but that's another story I suppose ...) I'd prefer the roxygenation to be part of the standard build/INSTALL system, so my plan is to write configure and configure.win which would call roxygenize to generate Rd. I can appreciate the desire to make the "true" sources available. At the same time, I think one should very carefully consider the expense of external dependencies on a package. One could view doc generation along the same lines as configure script generation -- a compilation step that can be done once instead of by all those who install and as a result reduce the depencency burden of those wanting to install the package. Configure scripts are almost universally included pre-built in distribution source packages so that users do not need to have the right version of autoconf/automake. The kind of configure[.win] scripts I am using are very simplistic and do not come from autoconf, etc ... something like this to compile the java source code using the ant package : #!/bin/bash cd inst/java_src "${R_HOME}/bin/Rscript" -e "ant::ant()" In other words, are you sure you want to require folks to install roxygen (or whatever) in order to install your package? Making it easy to do so is great, but in general if you can find a way to reduce dependencies and have your package work, that is better. :-) That is exactly what I am trying to do here, those who build the package are not necessarily the same as those who install it, so installation would not depend on roxygen. And Uwe is very right that what I am looking for is indeed __build__ time rather than __install__ time. I think you should talk to Manuel whose intention really was the usage you mentioned above (i.e. before or at build time). Best, Uwe + seth __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Probability of data values form empirical distribution
Hello, Â Could someone help me please and to tell how to get the probability from empirical distribution (not parametric) for each data value (R function). For example, for normal distribution there is such a function like: Â âpnorm(q, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)â Â I need the same function only for the empirical distribution (which does not correspond to any typical distribution). R plots the density function of any data: Â âplot(density(x))â Â I need to find out the probability for each data value from this plot-line. Â Best regards, Lina [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Probability of data values form empirical distribution
The function ecdf(x) computes the empirical cdf from data in the vector x. You can plot it with plot(ecdf(x)), or compute the emp. cdf at new values, e.g. my.cdf <- ecdf(x) my.cdf( 0:3 ) # computes the emp. cdf at 0,1,2,3 John ... John P. Nolan Math/Stat Department 227 Gray Hall American University 4400 Massachusetts Avenue, NW Washington, DC 20016-8050 jpno...@american.edu 202.885.3140 voice 202.885.3155 fax http://academic2.american.edu/~jpnolan ... -r-devel-boun...@r-project.org wrote: - To: R help From: Lina Rusyte Sent by: r-devel-boun...@r-project.org Date: 09/29/2009 04:51AM Cc: R devel Subject: [Rd] Probability of data values form empirical distribution Hello, à Could someone help me please and to tell how to get the probability from empirical distribution (not parametric) for each data value (R function). For example, for normal distribution there is such a function like: à ââ¬Åpnorm(q, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)ââ¬Â à I need the same function only for the empirical distribution (which does not correspond to any typical distribution). R plots the density function of any data: à ââ¬Åplot(density(x))ââ¬Â à I need to find out the probability for each data value from this plot-line. à Best regards, Lina [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] How do I access class slots from C?
Hi I'm trying to implement something similar to the following R snippet using C. I seem to have hit the wall on accessing class slots using C. library(fPortfolio) lppData <- 100 * LPP2005.RET[, 1:6] ewSpec <- portfolioSpec() nAssets <- ncol(lppData) setWeights(ewSpec) <- rep(1/nAssets, times = nAssets) ewPortfolio <- feasiblePortfolio( data = lppData, spec = ewSpec, constraints = "LongOnly") ewSpec is an object of type Portfolio Spec which has the following slots: model slot type = "MV" a string value optimize = "minRisk" a string value estimator = "covEstimator" a function name tailRisk = list()a list params = list(alpha=0.05, a=1, ...) a list portfolio slot a list weights = NULL a numeric vector targetReturn = NULL a numeric value targetRisk = NULLa numeric value riskFreeRate = 0 a numeric value nFrontierPoints = 50 an integer value status = NA) a integer value optim slot a list solver = "solveRquadprog"a function names objective = NULL function names options = list() a list with parameters control = list() a list with controls trace = FALSE) a logical messages slot: a list list = list()a list I want to set the weights so that I can compute a feasiblePortfolio. Unfortunately I cannot figure out how to do this from C. Here is what I wrote so far: #include #include #include #include #include int main(int argc, char** argv) { SEXP e,c,portSpec,portData,portConstr,portVal,portWeights,tsAssets,tsReturns,nAssets,reciprocal; int errorOccurred,nx,ny,i,j; double *v; const char *x,*y; Rf_initEmbeddedR(argc, argv); // loading fPortfolio PROTECT(e = lang2(install("library"), mkString("fPortfolio"))); R_tryEval(e, R_GlobalEnv, NULL); UNPROTECT(1); // creating a default portfolioSpec object PROTECT(e=lang1(install("portfolioSpec"))); PROTECT(portSpec=R_tryEval(e,R_GlobalEnv, NULL)); // creating a portfolioData object PROTECT(e=lang4(install("c"),mkString("SBI"),mkString("SPI"),mkString("SII"))); PROTECT(tsAssets=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang4(install("["),install("SWX.RET"),R_MissingArg,tsAssets)); PROTECT(tsReturns=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang3(install("*"),ScalarInteger(100),tsReturns)); PROTECT(tsReturns=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang3(install("portfolioData"),tsReturns,portSpec)); PROTECT(portData=R_tryEval(e,R_GlobalEnv,NULL)); // Creating a portfolio constraints string PROTECT(portConstr=mkString("LongOnly")); // Setting weights PROTECT(e=lang2(install("ncol"),tsReturns)); PROTECT(nAssets=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang3(install("/"),ScalarInteger(1),nAssets)); PROTECT(reciprocal=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang3(install("rep"),reciprocal,nAssets)); PROTECT(portWeights=R_tryEval(e,R_GlobalEnv,NULL)); // Right now the program crashes here. It says: Cannot find function "setWeights" // How do I set the weights? It's a standard numeric vector. I'm confused on access class slots from C. // Not much is writted on this in the R extensions manual. PROTECT(e=lang3(install("setWeights"),portSpec,portWeights)); PROTECT(portSpec=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang2(install("print"),portSpec)); R_tryEval(e,R_GlobalEnv,NULL); UNPROTECT(3); Rf_endEmbeddedR(0); return 0; } Regards Abhijit Bera [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Problem installing RMAGEML package
Hi all, I ran in to a problem while trying to install RMAGEML package. /usr/bin/ld: cannot find -ljava . (please look at the bottom for details of the error) I have set the following in ~/.bashrc file. export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64 export LD_LIBRARY_PATH=/home/mamun/R-2.9.0/lib64/R/library/rJava/jri:/home/mamun/R-2.9.0/lib64/R/lib:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64/native_threads My system details: linux version - Fedora 11, java version - java-1.6.0-openjdk-1.6.0.0.x86_64 R-version - 2.9.0 Any suggestion is welcome. thanks in advance. regards, Mamun ** Details of the problem : ** rmageml.c: In function updateMAGEML: rmageml.c:599: warning: cast from pointer to integer of different size gcc -std=gnu99 -shared -L/usr/local/lib64 -o RMAGEML.so rmageml.o -L/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/jre/lib/amd64 -L/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/jre/lib/i386 -ljava -L/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/jre/lib/amd64/server -L/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/jre/lib/i386/client -ljvm -L/home/mamun/R-2.9.0/lib64/R/lib -lR /usr/bin/ld: cannot find -ljava collect2: ld returned 1 exit status make: *** [RMAGEML.so] Error 1 ERROR: compilation failed for package RMAGEML * Removing /home/mamun/R-2.9.0/lib64/R/library/RMAGEML _ Show them the way! Add maps and directions to your party invites. [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How do I access class slots from C?
Hi, There is a GET_SLOT macro in Rdefines.h Cheers, Romain On 09/29/2009 04:28 PM, Abhijit Bera wrote: Hi I'm trying to implement something similar to the following R snippet using C. I seem to have hit the wall on accessing class slots using C. library(fPortfolio) lppData<- 100 * LPP2005.RET[, 1:6] ewSpec<- portfolioSpec() nAssets<- ncol(lppData) setWeights(ewSpec)<- rep(1/nAssets, times = nAssets) ewPortfolio<- feasiblePortfolio( data = lppData, spec = ewSpec, constraints = "LongOnly") ewSpec is an object of type Portfolio Spec which has the following slots: model slot type = "MV" a string value optimize = "minRisk" a string value estimator = "covEstimator" a function name tailRisk = list()a list params = list(alpha=0.05, a=1, ...) a list portfolio slot a list weights = NULL a numeric vector targetReturn = NULL a numeric value targetRisk = NULLa numeric value riskFreeRate = 0 a numeric value nFrontierPoints = 50 an integer value status = NA) a integer value optim slot a list solver = "solveRquadprog"a function names objective = NULL function names options = list() a list with parameters control = list() a list with controls trace = FALSE) a logical messages slot: a list list = list()a list I want to set the weights so that I can compute a feasiblePortfolio. Unfortunately I cannot figure out how to do this from C. Here is what I wrote so far: #include #include #include #include #include int main(int argc, char** argv) { SEXP e,c,portSpec,portData,portConstr,portVal,portWeights,tsAssets,tsReturns,nAssets,reciprocal; int errorOccurred,nx,ny,i,j; double *v; const char *x,*y; Rf_initEmbeddedR(argc, argv); // loading fPortfolio PROTECT(e = lang2(install("library"), mkString("fPortfolio"))); R_tryEval(e, R_GlobalEnv, NULL); UNPROTECT(1); // creating a default portfolioSpec object PROTECT(e=lang1(install("portfolioSpec"))); PROTECT(portSpec=R_tryEval(e,R_GlobalEnv, NULL)); // creating a portfolioData object PROTECT(e=lang4(install("c"),mkString("SBI"),mkString("SPI"),mkString("SII"))); PROTECT(tsAssets=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang4(install("["),install("SWX.RET"),R_MissingArg,tsAssets)); PROTECT(tsReturns=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang3(install("*"),ScalarInteger(100),tsReturns)); PROTECT(tsReturns=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang3(install("portfolioData"),tsReturns,portSpec)); PROTECT(portData=R_tryEval(e,R_GlobalEnv,NULL)); // Creating a portfolio constraints string PROTECT(portConstr=mkString("LongOnly")); // Setting weights PROTECT(e=lang2(install("ncol"),tsReturns)); PROTECT(nAssets=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang3(install("/"),ScalarInteger(1),nAssets)); PROTECT(reciprocal=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang3(install("rep"),reciprocal,nAssets)); PROTECT(portWeights=R_tryEval(e,R_GlobalEnv,NULL)); // Right now the program crashes here. It says: Cannot find function "setWeights" // How do I set the weights? It's a standard numeric vector. I'm confused on access class slots from C. // Not much is writted on this in the R extensions manual. PROTECT(e=lang3(install("setWeights"),portSpec,portWeights)); PROTECT(portSpec=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang2(install("print"),portSpec)); R_tryEval(e,R_GlobalEnv,NULL); UNPROTECT(3); Rf_endEmbeddedR(0); return 0; } Regards Abhijit Bera -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/ztCu : RGG #158:161: examples of package IDPmisc |- http://tr.im/yw8E : New R package : sos `- http://tr.im/y8y0 : search the graph gallery from R __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How do I access class slots from C?
Abhijit, as for your subject - it's GET_SLOT, but why don't you just use ParseVector and eval instead of hand- crafting C code that calls the evaluator? That latter is way more error prone and the error-handling is a nightmare (your current code is inefficient anyway so you don't gain anything). As for setWeights, you got the code wrong - if you want to mimic the R code then it's a call to the assignment "<-" - have a look at the parse result of "setWeights(ewSpec) <- rep(1/nAssets, times = nAssets)": @d58774 06 LANGSXP g0c0 [] @809008 01 SYMSXP g1c0 [MARK,gp=0x4000] "<-" @d59540 06 LANGSXP g0c0 [] @1a1af34 01 SYMSXP g0c0 [] "setWeights" @d59498 01 SYMSXP g0c0 [] "ewSpec" @d58720 06 LANGSXP g0c0 [] @814ac4 01 SYMSXP g1c0 [MARK,gp=0x4000] "rep" @d595b0 06 LANGSXP g0c0 [] @80ae44 01 SYMSXP g1c0 [MARK,gp=0x4000] "/" @1bf8ce8 14 REALSXP g0c1 [] (len=1, tl=0) 1 @1dbf1ac 01 SYMSXP g0c0 [MARK] "nAssets" TAG: @9450fc 01 SYMSXP g1c0 [MARK] "times" @1dbf1ac 01 SYMSXP g0c0 [MARK] "nAssets" Again, I think you would be far better off just using parse instead... Cheers, Simon PS: Your PROTECTs are way off-balance, and you don't need almost any of them - langX and listX protect all arguments On Sep 29, 2009, at 10:28 , Abhijit Bera wrote: Hi I'm trying to implement something similar to the following R snippet using C. I seem to have hit the wall on accessing class slots using C. library(fPortfolio) lppData <- 100 * LPP2005.RET[, 1:6] ewSpec <- portfolioSpec() nAssets <- ncol(lppData) setWeights(ewSpec) <- rep(1/nAssets, times = nAssets) ewPortfolio <- feasiblePortfolio( data = lppData, spec = ewSpec, constraints = "LongOnly") ewSpec is an object of type Portfolio Spec which has the following slots: model slot type = "MV" a string value optimize = "minRisk" a string value estimator = "covEstimator" a function name tailRisk = list()a list params = list(alpha=0.05, a=1, ...) a list portfolio slot a list weights = NULL a numeric vector targetReturn = NULL a numeric value targetRisk = NULLa numeric value riskFreeRate = 0 a numeric value nFrontierPoints = 50 an integer value status = NA) a integer value optim slot a list solver = "solveRquadprog"a function names objective = NULL function names options = list() a list with parameters control = list() a list with controls trace = FALSE) a logical messages slot: a list list = list()a list I want to set the weights so that I can compute a feasiblePortfolio. Unfortunately I cannot figure out how to do this from C. Here is what I wrote so far: #include #include #include #include #include int main(int argc, char** argv) { SEXP e ,c ,portSpec ,portData ,portConstr,portVal,portWeights,tsAssets,tsReturns,nAssets,reciprocal; int errorOccurred,nx,ny,i,j; double *v; const char *x,*y; Rf_initEmbeddedR(argc, argv); // loading fPortfolio PROTECT(e = lang2(install("library"), mkString("fPortfolio"))); R_tryEval(e, R_GlobalEnv, NULL); UNPROTECT(1); // creating a default portfolioSpec object PROTECT(e=lang1(install("portfolioSpec"))); PROTECT(portSpec=R_tryEval(e,R_GlobalEnv, NULL)); // creating a portfolioData object PROTECT (e =lang4(install("c"),mkString("SBI"),mkString("SPI"),mkString("SII"))); PROTECT(tsAssets=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT (e=lang4(install("["),install("SWX.RET"),R_MissingArg,tsAssets)); PROTECT(tsReturns=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang3(install("*"),ScalarInteger(100),tsReturns)); PROTECT(tsReturns=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang3(install("portfolioData"),tsReturns,portSpec)); PROTECT(portData=R_tryEval(e,R_GlobalEnv,NULL)); // Creating a portfolio constraints string PROTECT(portConstr=mkString("LongOnly")); // Setting weights PROTECT(e=lang2(install("ncol"),tsReturns)); PROTECT(nAssets=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang3(install("/"),ScalarInteger(1),nAssets)); PROTECT(reciprocal=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang3(install("rep"),reciprocal,nAssets)); PROTECT(portWeights=R_tryEval(e,R_GlobalEnv,NULL)); // Right now the program crashes here. It says: Cannot find function "setWeights" // How do I set the weights? It's a standard numeric vector. I'm confused on access class slots from C. // Not much is writted on this in the R extensions manual. PROTECT(e=lang3(install("setWeights"),portSpec,portWeights)); PROTECT(portSpec=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang2(install("print"),portSpec)); R_tryEval(e,R_GlobalEnv,NULL); UNPROTECT(3); Rf_endEmbeddedR(0); ret
Re: [Rd] How do I access class slots from C?
Simon Urbanek wrote: Abhijit, as for your subject - it's GET_SLOT, but why don't you just use ParseVector and eval instead of hand-crafting C code that calls the evaluator? That latter is way more error prone and the error-handling is a nightmare (your current code is inefficient anyway so you don't gain anything). My 2 cents: constructing language calls seems much more appropriate than parsing expressions when the values to be used are from programming variables, as is likely the case in most real applications? And accessing slots with GET_SLOT seems to break the (hard-won) abstraction layer of S4, so better to call the R accessors (even when this is inefficient computationally) especially when using objects from packates whose internals you do not control. One particular part of the code below PROTECT(e=lang4(install("c"),mkString("SBI"),mkString("SPI"),mkString("SII"))); could be re-written as SEXP x = PROTECT(NEW_CHARACTER(3)); SET_STRING_ELT(x, 0, mkChar("SBI")); etc In the original, although the outer PROTECT is unnecessary, I wonder about the mString()... calls, which are not guaranteed to be evaluated in order and produce unprotected CHARSXPs (prior to being protected inside lang4). I'm not really sure about the mkChar() in the above, either, and whether there is an opportunity for garbage collection in SET_VECTOR_ELT. Martin As for setWeights, you got the code wrong - if you want to mimic the R code then it's a call to the assignment "<-" - have a look at the parse result of "setWeights(ewSpec) <- rep(1/nAssets, times = nAssets)": @d58774 06 LANGSXP g0c0 [] @809008 01 SYMSXP g1c0 [MARK,gp=0x4000] "<-" @d59540 06 LANGSXP g0c0 [] @1a1af34 01 SYMSXP g0c0 [] "setWeights" @d59498 01 SYMSXP g0c0 [] "ewSpec" @d58720 06 LANGSXP g0c0 [] @814ac4 01 SYMSXP g1c0 [MARK,gp=0x4000] "rep" @d595b0 06 LANGSXP g0c0 [] @80ae44 01 SYMSXP g1c0 [MARK,gp=0x4000] "/" @1bf8ce8 14 REALSXP g0c1 [] (len=1, tl=0) 1 @1dbf1ac 01 SYMSXP g0c0 [MARK] "nAssets" TAG: @9450fc 01 SYMSXP g1c0 [MARK] "times" @1dbf1ac 01 SYMSXP g0c0 [MARK] "nAssets" Again, I think you would be far better off just using parse instead... Cheers, Simon PS: Your PROTECTs are way off-balance, and you don't need almost any of them - langX and listX protect all arguments On Sep 29, 2009, at 10:28 , Abhijit Bera wrote: Hi I'm trying to implement something similar to the following R snippet using C. I seem to have hit the wall on accessing class slots using C. library(fPortfolio) lppData <- 100 * LPP2005.RET[, 1:6] ewSpec <- portfolioSpec() nAssets <- ncol(lppData) setWeights(ewSpec) <- rep(1/nAssets, times = nAssets) ewPortfolio <- feasiblePortfolio( data = lppData, spec = ewSpec, constraints = "LongOnly") ewSpec is an object of type Portfolio Spec which has the following slots: model slot type = "MV" a string value optimize = "minRisk" a string value estimator = "covEstimator" a function name tailRisk = list()a list params = list(alpha=0.05, a=1, ...) a list portfolio slot a list weights = NULL a numeric vector targetReturn = NULL a numeric value targetRisk = NULLa numeric value riskFreeRate = 0 a numeric value nFrontierPoints = 50 an integer value status = NA) a integer value optim slot a list solver = "solveRquadprog"a function names objective = NULL function names options = list() a list with parameters control = list() a list with controls trace = FALSE) a logical messages slot: a list list = list()a list I want to set the weights so that I can compute a feasiblePortfolio. Unfortunately I cannot figure out how to do this from C. Here is what I wrote so far: #include #include #include #include #include int main(int argc, char** argv) { SEXP e,c,portSpec,portData,portConstr,portVal,portWeights,tsAssets,tsReturns,nAssets,reciprocal; int errorOccurred,nx,ny,i,j; double *v; const char *x,*y; Rf_initEmbeddedR(argc, argv); // loading fPortfolio PROTECT(e = lang2(install("library"), mkString("fPortfolio"))); R_tryEval(e, R_GlobalEnv, NULL); UNPROTECT(1); // creating a default portfolioSpec object PROTECT(e=lang1(install("portfolioSpec"))); PROTECT(portSpec=R_tryEval(e,R_GlobalEnv, NULL)); // creating a portfolioData object PROTECT(e=lang4(install("c"),mkString("SBI"),mkString("SPI"),mkString("SII"))); PROTECT(tsAssets=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang4(install("["),install("SWX.RET"),R_MissingArg,tsAssets)); PROTECT(tsReturns=R_tryEval(e,R_GlobalEnv,NULL)); PROTECT(e=lang3(install("*"),ScalarInteger(100),tsReturns)); PROTECT(tsReturns=R_tryEval(e,R_GlobalEnv,NU
Re: [Rd] model.matrix troubles with AlgDesign
Hi Ulrike, It looks like 'aus' is created by fac.design(); is there any reason why you can't add the variable y <- 1:nrow(aus) to this data frame and use y as the response in your formula? Otherwise I think aus needs to be in the environment of frml (or frml needs to be given the environment of aus). Heather Ulrike Groemping wrote: > Dear DevelopeRs, > > in continuing with my suite of packages on experimental design, I am stuck > with an issue that appears to be related to package AlgDesign - I have tried > to get it solved by Bob Wheeler, but he seems to be stuck as well. > > Whenever AlgDesign is loaded, some of my code does not work any more. For > example, in a fresh R session: > > require(DoE.base) > fac.design(nlevels=c(2,6,2)) > require(AlgDesign) > fac.design(nlevels=c(2,6,2)) >> Error in nrow(aus) : object 'aus' not found > > The reason seems to be that AlgDesign creates a function > model.matrix.formula that only finds variables that are in the global > environment and variables that are in the data frame given with the formula, > but not calculation results from the intermediate calling environment. > > Results from traceback(): > 9: nrow(aus) > 8: eval(expr, envir, enclos) > 7: eval(predvars, data, env) > 6: model.frame.default(object, data, xlev = xlev) > 5: model.frame(object, data, xlev = xlev) > 4: model.matrix.default(frml, data, ...) > 3: model.matrix.formula(1:nrow(aus) ~ ., data = aus) > 2: model.matrix(1:nrow(aus) ~ ., data = aus) > 1: fac.design(nlevels = c(2, 6, 2)) > > If I reset model.matrix.formula to model.matrix.default, the problem > disappears (but AlgDesign's comfort functions for squares etc. do not work > any longer). In this particular case, I can also avoid the issue by > modifying the formula in fac.design, removing the left-hand side. But this > just means to wait for the next place where troubles occur. Between 3 and 4 > of the traceback(), AlgDesign's function model.matrix.formula modifies the > formula frml using AlgDesign's function expand.formula: > > model.matrix.formula <- function (frml, data = sys.frame(sys.parent()), ...) > { > if (!missing(data)) { > if (!inherits(data, "data.frame")) > stop("data must be a data.frame") > if (!inherits(frml, "formula")) > stop("frml must be a formuls") > frml <- expand.formula(frml, colnames(data)) > } > model.matrix.default(frml, data, ...) > } > > > I have looked at expand.formula as well, and I've been wondering whether a > simple fix can be found by adding environment information (which?) within > that function (I believe that the relevant portion of the code is included > below): > > expand.formula <- function (frml, varNames, const = TRUE, numerics = NULL) > { > ## omitted quite a bit of code > ##... > frml <- deparse(frml, width = 500) > while ((0 != (pos <- findFunction("quad", frml))[1]) || (0 != > (pos <- findFunction("cubicS", frml))[1]) || (0 != (pos <- > findFunction("cubic", > frml))[1])) { > prog <- substr(frml, pos[1], pos[2]) > strHead <- substr(frml, 1, pos[1] - 1) > strTail <- substr(frml, pos[2] + 1, nchar(frml)) > prog <- eval(parse(text = prog)) > frml <- paste(strHead, prog, strTail, sep = "") > } > if (0 != (pos <- findDot(".", frml))[1]) { > strHead <- substr(frml, 1, pos[1] - 1) > strTail <- substr(frml, pos[2] + 1, nchar(frml)) > prog <- eval(parse(text = "doDot()")) > frml <- paste(strHead, prog, strTail, sep = "") > } > if (!const) > frml <- paste(frml, "+0", sep = "") > frml <- as.formula(frml) > frml > } > > Any help would be greatly appreciated. > > Regards, Ulrike > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Downloading R-2.10.0
On 9/29/2009 4:03 AM, Uwe Ligges wrote: Duncan is travelling and may not yet have updated his scripts to make alpha versions available (rather than R-devel), please be patient. I'm back now, but stuck in a meeting all afternoon. I should be able to get the builds started tonight, but there may be some glitches... Duncan Murdoch Best, Uwe Ligges Gabor Grothendieck wrote: For Windows, this page http://cran.r-project.org/bin/windows/base/ gives a link to download - R 2.9.2 - r-patched (R 2.9.2 patched) - old releases and - r-devel (R 2.11.0) but there is no obvious link to R 2.10.0. From where do we download that? __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] model.matrix troubles with AlgDesign
Hi Heather, thanks, I would be able to add the variable y <- 1:nrow(aus), I would even be able to omit these. What concerns me is the fact that the presence of function model.matrix.formula in package AlgDesign will stop model.matrix from working as expected in further situations that I have not spotted yet. For the future development of package DoE.wrapper, I would like to include AlgDesign in the Depends field, and that would mean that the package would then stop user functions with perfectly valid code from working correctly. So I would like to find a way to modify model.matrix.formula or expand.formula from AlgDesign so that AlgDesign stops messing up usages of model.matrix in other contexts. I think that the solution may perhaps lie in assigning the right environment to frml in expand.formula, but I am not familiar enough with assigning environments to know what the right strategy would be. Any suggestions ? Regards, Ulrike Heather Turner wrote: > > Hi Ulrike, > > It looks like 'aus' is created by fac.design(); is there any reason why > you can't add the variable > y <- 1:nrow(aus) > to this data frame and use y as the response in your formula? > > Otherwise I think aus needs to be in the environment of frml (or frml > needs to be given the environment of aus). > > Heather > > Ulrike Groemping wrote: >> Dear DevelopeRs, >> >> in continuing with my suite of packages on experimental design, I am >> stuck >> with an issue that appears to be related to package AlgDesign - I have >> tried >> to get it solved by Bob Wheeler, but he seems to be stuck as well. >> >> Whenever AlgDesign is loaded, some of my code does not work any more. For >> example, in a fresh R session: >> >> require(DoE.base) >> fac.design(nlevels=c(2,6,2)) >> require(AlgDesign) >> fac.design(nlevels=c(2,6,2)) >>> Error in nrow(aus) : object 'aus' not found >> >> The reason seems to be that AlgDesign creates a function >> model.matrix.formula that only finds variables that are in the global >> environment and variables that are in the data frame given with the >> formula, >> but not calculation results from the intermediate calling environment. >> >> Results from traceback(): >> 9: nrow(aus) >> 8: eval(expr, envir, enclos) >> 7: eval(predvars, data, env) >> 6: model.frame.default(object, data, xlev = xlev) >> 5: model.frame(object, data, xlev = xlev) >> 4: model.matrix.default(frml, data, ...) >> 3: model.matrix.formula(1:nrow(aus) ~ ., data = aus) >> 2: model.matrix(1:nrow(aus) ~ ., data = aus) >> 1: fac.design(nlevels = c(2, 6, 2)) >> >> If I reset model.matrix.formula to model.matrix.default, the problem >> disappears (but AlgDesign's comfort functions for squares etc. do not >> work >> any longer). In this particular case, I can also avoid the issue by >> modifying the formula in fac.design, removing the left-hand side. But >> this >> just means to wait for the next place where troubles occur. Between 3 and >> 4 >> of the traceback(), AlgDesign's function model.matrix.formula modifies >> the >> formula frml using AlgDesign's function expand.formula: >> >> model.matrix.formula <- function (frml, data = sys.frame(sys.parent()), >> ...) >> { >> if (!missing(data)) { >> if (!inherits(data, "data.frame")) >> stop("data must be a data.frame") >> if (!inherits(frml, "formula")) >> stop("frml must be a formuls") >> frml <- expand.formula(frml, colnames(data)) >> } >> model.matrix.default(frml, data, ...) >> } >> >> >> I have looked at expand.formula as well, and I've been wondering whether >> a >> simple fix can be found by adding environment information (which?) within >> that function (I believe that the relevant portion of the code is >> included >> below): >> >> expand.formula <- function (frml, varNames, const = TRUE, numerics = >> NULL) >> { >> ## omitted quite a bit of code >> ##... >> frml <- deparse(frml, width = 500) >> while ((0 != (pos <- findFunction("quad", frml))[1]) || (0 != >> (pos <- findFunction("cubicS", frml))[1]) || (0 != (pos <- >> findFunction("cubic", >> frml))[1])) { >> prog <- substr(frml, pos[1], pos[2]) >> strHead <- substr(frml, 1, pos[1] - 1) >> strTail <- substr(frml, pos[2] + 1, nchar(frml)) >> prog <- eval(parse(text = prog)) >> frml <- paste(strHead, prog, strTail, sep = "") >> } >> if (0 != (pos <- findDot(".", frml))[1]) { >> strHead <- substr(frml, 1, pos[1] - 1) >> strTail <- substr(frml, pos[2] + 1, nchar(frml)) >> prog <- eval(parse(text = "doDot()")) >> frml <- paste(strHead, prog, strTail, sep = "") >> } >> if (!const) >> frml <- paste(frml, "+0", sep = "") >> frml <- as.formula(frml) >> frml >> } >> >> Any help would be greatly appreciated. >> >> Regards, Ulrike >> > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/
Re: [Rd] How do I access class slots from C?
MArtin, On Sep 29, 2009, at 12:17 , Martin Morgan wrote: Simon Urbanek wrote: Abhijit, as for your subject - it's GET_SLOT, but why don't you just use ParseVector and eval instead of hand- crafting C code that calls the evaluator? That latter is way more error prone and the error-handling is a nightmare (your current code is inefficient anyway so you don't gain anything). My 2 cents: constructing language calls seems much more appropriate than parsing expressions when the values to be used are from programming variables, as is likely the case in most real applications? Yes, but not in this case - it's all just replication of a script that could be evaluated with one call, there are no native objects involved. As soon as you start using more than one eval in the C code, it is very likely not the right way to go. I do agree that constructed expressions are useful if you have a) a very short call that cannot be easily done at C level or b) it involves unassigned objects generated in the C code -- but neither it the case here. And accessing slots with GET_SLOT seems to break the (hard-won) abstraction layer of S4, so better to call the R accessors (even when this is inefficient computationally) especially when using objects from packates whose internals you do not control. Agreed, again something that could be prevented with parse + eval ;). One particular part of the code below PROTECT (e =lang4(install("c"),mkString("SBI"),mkString("SPI"),mkString("SII"))); could be re-written as SEXP x = PROTECT(NEW_CHARACTER(3)); SET_STRING_ELT(x, 0, mkChar("SBI")); etc In the original, although the outer PROTECT is unnecessary, I wonder about the mString()... calls, which are not guaranteed to be evaluated in order and produce unprotected CHARSXPs (prior to being protected inside lang4). I'm not really sure about the mkChar() in the above, either, and whether there is an opportunity for garbage collection in SET_VECTOR_ELT. CHARSXPs are always protected by enclosing STRSXP and SET_STRING_ELT(x, i, mkChar()) is always safe. And yes, the lang4 "c" construct is a bad idea. Cheers, Simon As for setWeights, you got the code wrong - if you want to mimic the R code then it's a call to the assignment "<-" - have a look at the parse result of "setWeights(ewSpec) <- rep(1/nAssets, times = nAssets)": @d58774 06 LANGSXP g0c0 [] @809008 01 SYMSXP g1c0 [MARK,gp=0x4000] "<-" @d59540 06 LANGSXP g0c0 [] @1a1af34 01 SYMSXP g0c0 [] "setWeights" @d59498 01 SYMSXP g0c0 [] "ewSpec" @d58720 06 LANGSXP g0c0 [] @814ac4 01 SYMSXP g1c0 [MARK,gp=0x4000] "rep" @d595b0 06 LANGSXP g0c0 [] @80ae44 01 SYMSXP g1c0 [MARK,gp=0x4000] "/" @1bf8ce8 14 REALSXP g0c1 [] (len=1, tl=0) 1 @1dbf1ac 01 SYMSXP g0c0 [MARK] "nAssets" TAG: @9450fc 01 SYMSXP g1c0 [MARK] "times" @1dbf1ac 01 SYMSXP g0c0 [MARK] "nAssets" Again, I think you would be far better off just using parse instead... Cheers, Simon PS: Your PROTECTs are way off-balance, and you don't need almost any of them - langX and listX protect all arguments On Sep 29, 2009, at 10:28 , Abhijit Bera wrote: Hi I'm trying to implement something similar to the following R snippet using C. I seem to have hit the wall on accessing class slots using C. library(fPortfolio) lppData <- 100 * LPP2005.RET[, 1:6] ewSpec <- portfolioSpec() nAssets <- ncol(lppData) setWeights(ewSpec) <- rep(1/nAssets, times = nAssets) ewPortfolio <- feasiblePortfolio( data = lppData, spec = ewSpec, constraints = "LongOnly") ewSpec is an object of type Portfolio Spec which has the following slots: model slot type = "MV" a string value optimize = "minRisk" a string value estimator = "covEstimator" a function name tailRisk = list()a list params = list(alpha=0.05, a=1, ...) a list portfolio slot a list weights = NULL a numeric vector targetReturn = NULL a numeric value targetRisk = NULLa numeric value riskFreeRate = 0 a numeric value nFrontierPoints = 50 an integer value status = NA) a integer value optim slot a list solver = "solveRquadprog"a function names objective = NULL function names options = list() a list with parameters control = list() a list with controls trace = FALSE) a logical messages slot: a list list = list()a list I want to set the weights so that I can compute a feasiblePortfolio. Unfortunately I cannot figure out how to do this from C. Here is what I wrote so far: #include #include #include #include #include int main(int argc, char** argv) { SEXP e ,c ,portSpec ,portData ,portConstr ,portVal,portWeights,tsAssets,tsReturns,nAssets,reciprocal; int errorOccurred,nx,ny,i,j; double *v;
Re: [Rd] enabling core dumps
... If I launch gdb this way I don't have any means to navigate through previously executed gdb lines using M-p and M-n, but following a (gdb) run or (gdb) continue I can use M-p and M-n to recall previous R commands If I launch gdb in other ways M-p and M-n function as expected. I suppose there is a confusion between gdb's M-p and ESS's M-p so that M-p only functions in the ESS session. I quite like running gdb using R's -d flag, but not being able to navigate through the line history is sub-optimal. I'd be interested to hear if other people running gdb this way encountered this problem and how they resolved it. This had a one line solution (section 19.3, page 216, gdb manual) gdb> set history save on __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How do I access class slots from C?
This is so much fun. The C code posted wasn't exactly legible. So here is a new C++ variant that I just committed to the RInside SVN as a new example. And it mine works (against RInide and Rcpp as on CRAN): e...@ron:~/svn/rinside/pkg/inst/examples> ./rinside_sample4 Package 'sn', 0.4-12 (2009-03-21). Type 'help(SN)' for summary information Using the GLPK callable library version 4.37 Title: MV Feasible Portfolio Estimator: covEstimator Solver:solveRquadprog Optimize: minRisk Constraints: LongOnly Portfolio Weights: SBI SPI SII LMI MPI ALT 0.1 0.1 0.1 0.1 0.3 0.3 Covariance Risk Budgets: SBI SPI SII LMI MPI ALT -0.0038 0.1423 0.0125 -0.0058 0.4862 0.3686 Target Return and Risks: mean muCov Sigma CVaRVaR 0.0548 0.0548 0.4371 0.4371 1.0751 0.6609 Description: Tue Sep 29 13:43:36 2009 by user: SBI-0.00380065 SPI 0.142261 SII 0.0125242 LMI-0.00576251 MPI 0.486228 ALT 0.368551 e...@ron:~/svn/rinside/pkg/inst/examples> The final few lines are C++ accessing the result, earlier in the code I assign the weight vector from C++ as you desired from C. All with error checking / exception handling and what have in under 60 lines of (IMHO more readable) code -- see below. Dirk // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*- // // Another simple example inspired by an r-devel mail by Abhijit Bera // // Copyright (C) 2009 Dirk Eddelbuettel and GPL'ed #include "RInside.h"// for the embedded R via RInside #include "Rcpp.h" // for the R / Cpp interface used for transfer #include int main(int argc, char *argv[]) { try { RInside R(argc, argv); // create an embedded R instance SEXP ans; std::string txt = "suppressMessages(library(fPortfolio))"; if (R.parseEvalQ(txt)) // load library, no return value throw std::runtime_error("R cannot evaluate '" + txt + "'"); txt = "lppData <- 100 * LPP2005.RET[, 1:6]; " "ewSpec <- portfolioSpec(); " "nAssets <- ncol(lppData); "; if (R.parseEval(txt, ans)) // prepare problem throw std::runtime_error("R cannot evaluate '" + txt + "'"); const double dvec[6] = { 0.1, 0.1, 0.1, 0.1, 0.3, 0.3 }; // choose any weights you want const std::vector w(dvec, &dvec[6]); R.assign( w, "weightsvec"); // assign STL vector to R's 'weightsvec' variable txt = "setWeights(ewSpec) <- weightsvec"; if (R.parseEvalQ(txt)) // evaluate assignment throw std::runtime_error("R cannot evaluate '" + txt + "'"); txt = "ewPortfolio <- feasiblePortfolio(data = lppData, spec = ewSpec, constraints = \"LongOnly\"); " "print(ewPortfolio); " "vec <- getCovRiskBudgets(ewportfo...@portfolio)"; if (R.parseEval(txt, ans)) // assign covRiskBudget weights to ans throw std::runtime_error("R cannot evaluate '" + txt + "'"); RcppVector V(ans); // convert SEXP variable to an RcppMatrix R.parseEval("names(vec)", ans); // assign columns names to ans RcppStringVector names(ans); for (int i=0; ihttps://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Problems connecting to httpd help server with some browsers
Hello, sorry to provide only very little testing, but with the release date nearing, I thought it better to report this quickly than to wait for an uncertain period until I find more time. I'm observing strange problems connecting to the httpd help server with konqueror (KDE 4.3.1): options (help_type="html") options (browser="konqueror") help ("print") The first page opens in a konqueror window as expected. However, clicking on any links does not have any result. Konqueror just says "waiting for reply" forever. There does not even seem to be a timeout. Pointing the same browser instance to some other url works fine. Trying to use lynx as a browser (since it's a terminal browser, you need open lynx in a separate terminal and point it to the httpd help server manually) causes lynx to become unresponsive. Both konqueror and lynx are able to browse the static html files just fine. Firefox and Opera work fine with the httpd server on the same computer. Does anybody else see similar symptoms? Regards Thomas > R.version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status Under development (unstable) major 2 minor 11.0 year 2009 month 09 day29 svn rev49866 language R version.string R version 2.11.0 Under development (unstable) (2009-09-29 r49866) signature.asc Description: This is a digitally signed message part. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] model.matrix troubles with AlgDesign
Ah ok, I get the problem now. I think you just need to modify model.matrix.formula as follows model.matrix.formula <- function (frml, data = sys.frame(sys.parent()), ...) { if (!missing(data)) { if (!inherits(data, "data.frame")) stop("data must be a data.frame") if (!inherits(frml, "formula")) stop("frml must be a formuls") env <- environment(frml) frml <- expand.formula(frml, colnames(data)) environment(frml) <- env } model.matrix.default(frml, data, ...) } or the equivalent could be done inside expand.formula, which might be neater actually. Hope that fixes it, Heather Ulrike Groemping wrote: > Hi Heather, > > thanks, I would be able to add the variable y <- 1:nrow(aus), I would even > be able to omit these. > What concerns me is the fact that the presence of function > model.matrix.formula in package AlgDesign will stop model.matrix from > working as expected in further situations that I have not spotted yet. > > For the future development of package DoE.wrapper, I would like to include > AlgDesign in the Depends field, and that would mean that the package would > then stop user functions with perfectly valid code from working correctly. > So I would like to find a way to modify model.matrix.formula or > expand.formula from AlgDesign so that AlgDesign stops messing up usages of > model.matrix in other contexts. I think that the solution may perhaps lie in > assigning the right environment to frml in expand.formula, but I am not > familiar enough with assigning environments to know what the right strategy > would be. > > Any suggestions ? > > Regards, > Ulrike > > > > Heather Turner wrote: >> Hi Ulrike, >> >> It looks like 'aus' is created by fac.design(); is there any reason why >> you can't add the variable >> y <- 1:nrow(aus) >> to this data frame and use y as the response in your formula? >> >> Otherwise I think aus needs to be in the environment of frml (or frml >> needs to be given the environment of aus). >> >> Heather >> >> Ulrike Groemping wrote: >>> Dear DevelopeRs, >>> >>> in continuing with my suite of packages on experimental design, I am >>> stuck >>> with an issue that appears to be related to package AlgDesign - I have >>> tried >>> to get it solved by Bob Wheeler, but he seems to be stuck as well. >>> >>> Whenever AlgDesign is loaded, some of my code does not work any more. For >>> example, in a fresh R session: >>> >>> require(DoE.base) >>> fac.design(nlevels=c(2,6,2)) >>> require(AlgDesign) >>> fac.design(nlevels=c(2,6,2)) Error in nrow(aus) : object 'aus' not found >>> The reason seems to be that AlgDesign creates a function >>> model.matrix.formula that only finds variables that are in the global >>> environment and variables that are in the data frame given with the >>> formula, >>> but not calculation results from the intermediate calling environment. >>> >>> Results from traceback(): >>> 9: nrow(aus) >>> 8: eval(expr, envir, enclos) >>> 7: eval(predvars, data, env) >>> 6: model.frame.default(object, data, xlev = xlev) >>> 5: model.frame(object, data, xlev = xlev) >>> 4: model.matrix.default(frml, data, ...) >>> 3: model.matrix.formula(1:nrow(aus) ~ ., data = aus) >>> 2: model.matrix(1:nrow(aus) ~ ., data = aus) >>> 1: fac.design(nlevels = c(2, 6, 2)) >>> >>> If I reset model.matrix.formula to model.matrix.default, the problem >>> disappears (but AlgDesign's comfort functions for squares etc. do not >>> work >>> any longer). In this particular case, I can also avoid the issue by >>> modifying the formula in fac.design, removing the left-hand side. But >>> this >>> just means to wait for the next place where troubles occur. Between 3 and >>> 4 >>> of the traceback(), AlgDesign's function model.matrix.formula modifies >>> the >>> formula frml using AlgDesign's function expand.formula: >>> >>> model.matrix.formula <- function (frml, data = sys.frame(sys.parent()), >>> ...) >>> { >>> if (!missing(data)) { >>> if (!inherits(data, "data.frame")) >>> stop("data must be a data.frame") >>> if (!inherits(frml, "formula")) >>> stop("frml must be a formuls") >>> frml <- expand.formula(frml, colnames(data)) >>> } >>> model.matrix.default(frml, data, ...) >>> } >>> >>> >>> I have looked at expand.formula as well, and I've been wondering whether >>> a >>> simple fix can be found by adding environment information (which?) within >>> that function (I believe that the relevant portion of the code is >>> included >>> below): >>> >>> expand.formula <- function (frml, varNames, const = TRUE, numerics = >>> NULL) >>> { >>> ## omitted quite a bit of code >>> ##... >>> frml <- deparse(frml, width = 500) >>> while ((0 != (pos <- findFunction("quad", frml))[1]) || (0 != >>> (pos <- findFunction("cubicS", frml))[1]) || (0 != (pos <- >>> findFunction("cubic", >>> frml))[1])) { >>> prog <- substr(f
Re: [Rd] Problems connecting to httpd help server with some browsers
Thomas, On Sep 29, 2009, at 15:15 , Thomas Friedrichsmeier wrote: Hello, sorry to provide only very little testing, but with the release date nearing, I thought it better to report this quickly than to wait for an uncertain period until I find more time. Yes, good thinking :). I'm observing strange problems connecting to the httpd help server with konqueror (KDE 4.3.1): options (help_type="html") options (browser="konqueror") help ("print") The first page opens in a konqueror window as expected. However, clicking on any links does not have any result. Konqueror just says "waiting for reply" forever. There does not even seem to be a timeout. Pointing the same browser instance to some other url works fine. Trying to use lynx as a browser (since it's a terminal browser, you need open lynx in a separate terminal and point it to the httpd help server manually) causes lynx to become unresponsive. I don't have konqueror at hand, so I have tested and fixed the lynx case (lynx is acting as an HTTP/1.0 client and expects non-persistent connection). With some luck the fix may solve the konqueror issue as well (although I'd be a bit surprised if konqueror was not 1.1- capable..). Thanks, Simon Both konqueror and lynx are able to browse the static html files just fine. Firefox and Opera work fine with the httpd server on the same computer. Does anybody else see similar symptoms? Regards Thomas R.version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status Under development (unstable) major 2 minor 11.0 year 2009 month 09 day29 svn rev49866 language R version.string R version 2.11.0 Under development (unstable) (2009-09-29 r49866) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Problems connecting to httpd help server with some browsers
Simon Urbanek wrote: [...] I don't have konqueror at hand, so I have tested and fixed the lynx case (lynx is acting as an HTTP/1.0 client and expects non-persistent connection). With some luck the fix may solve the konqueror issue as well (although I'd be a bit surprised if konqueror was not 1.1-capable..). Konqueror didn't like the extra newline in the Location header: Index: src/library/tools/R/dynamicHelp.R === --- src/library/tools/R/dynamicHelp.R (revision 49890) +++ src/library/tools/R/dynamicHelp.R (working copy) @@ -172,7 +172,7 @@ return(list(payload = paste('Redirect to "', basename(file), '"', sep=''), "content-type" = 'text/html', - header = paste('Location: ', file, '\n', sep=''), + header = paste('Location: ', file, sep=''), "status code" = 302L)) # temporary redirect } else if (length(file) > 1L) { paths <- dirname(dirname(file)) Jeff __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] unable to load shared library (Symbol not found: _PQbackendPID)
I can't get the RPostgreSQL library to load on OSX and have no idea where it's going wrong... > library( RPostgreSQL ) Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared library '/Users/hamannj/Library/R/2.9/library/ RPostgreSQL/libs/i386/RPostgreSQL.so': dlopen(/Users/hamannj/Library/R/2.9/library/RPostgreSQL/libs/i386/ RPostgreSQL.so, 6): Symbol not found: _PQbackendPID Referenced from: /Users/hamannj/Library/R/2.9/library/RPostgreSQL/ libs/i386/RPostgreSQL.so Expected in: flat namespace in /Users/hamannj/Library/R/2.9/library/RPostgreSQL/libs/i386/ RPostgreSQL.so Error: package/namespace load failed for 'RPostgreSQL' I've used this on OSX before and have had to recently rebuild... does anyone know if an older archive works? Jeff Hamann, PhD PO Box 1421 Corvallis, Oregon 97339-1421 541-754-2457 jeff.hamann[at]forestinformatics[dot]com http://www.forestinformatics.com [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] unable to load shared library (Symbol not found: _PQbackendPID)
Jeff, On 29 September 2009 at 17:50, Jeff Hamann wrote: | I can't get the RPostgreSQL library to load on OSX and have no idea | where it's going wrong... | | > library( RPostgreSQL ) | Error in dyn.load(file, DLLpath = DLLpath, ...) : |unable to load shared library '/Users/hamannj/Library/R/2.9/library/ | RPostgreSQL/libs/i386/RPostgreSQL.so': |dlopen(/Users/hamannj/Library/R/2.9/library/RPostgreSQL/libs/i386/ | RPostgreSQL.so, 6): Symbol not found: _PQbackendPID |Referenced from: /Users/hamannj/Library/R/2.9/library/RPostgreSQL/ | libs/i386/RPostgreSQL.so |Expected in: flat namespace | in /Users/hamannj/Library/R/2.9/library/RPostgreSQL/libs/i386/ | RPostgreSQL.so | Error: package/namespace load failed for 'RPostgreSQL' As you know, questions / complaints about contributed packages should go to the maintainer first, i.e. me. Now, I do not have access to OS X -- but Neil (CC'ed) kindly covers that angle. Maybe the two of you can sort this out? | I've used this on OSX before and have had to recently rebuild... does | anyone know if an older archive works? The current version works for other on OS X as far as I know. Dirk -- Three out of two people have difficulties with fractions. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How do I access class slots from C?
Hi Thanks all of you for your suggestions. I will put up my code shortly based on your suggestions. I wonder how the parsing and eval will work when most of my data comes in from an external source like a DB? Probably it would be more efficient to make an object? H... maybe it has to be a mix of parsing and eval? Yes, the lang4 c idea sucks. mkstring is better. Regards Abhijit On Tue, Sep 29, 2009 at 11:55 PM, Dirk Eddelbuettel wrote: > > This is so much fun. The C code posted wasn't exactly legible. So here is > a > new C++ variant that I just committed to the RInside SVN as a new example. > And it mine works (against RInide and Rcpp as on CRAN): > > e...@ron:~/svn/rinside/pkg/inst/examples> ./rinside_sample4 > Package 'sn', 0.4-12 (2009-03-21). Type 'help(SN)' for summary information > Using the GLPK callable library version 4.37 > > Title: > MV Feasible Portfolio > Estimator: covEstimator > Solver:solveRquadprog > Optimize: minRisk > Constraints: LongOnly > > Portfolio Weights: > SBI SPI SII LMI MPI ALT > 0.1 0.1 0.1 0.1 0.3 0.3 > > Covariance Risk Budgets: >SBI SPI SII LMI MPI ALT > -0.0038 0.1423 0.0125 -0.0058 0.4862 0.3686 > > Target Return and Risks: > mean muCov Sigma CVaRVaR > 0.0548 0.0548 0.4371 0.4371 1.0751 0.6609 > > Description: > Tue Sep 29 13:43:36 2009 by user: > SBI-0.00380065 > SPI 0.142261 > SII 0.0125242 > LMI-0.00576251 > MPI 0.486228 > ALT 0.368551 > e...@ron:~/svn/rinside/pkg/inst/examples> > > The final few lines are C++ accessing the result, earlier in the code I > assign the weight vector from C++ as you desired from C. All with error > checking / exception handling and what have in under 60 lines of (IMHO more > readable) code -- see below. > > Dirk > > // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*- > // > // Another simple example inspired by an r-devel mail by Abhijit Bera > // > // Copyright (C) 2009 Dirk Eddelbuettel and GPL'ed > > #include "RInside.h"// for the embedded R via RInside > #include "Rcpp.h" // for the R / Cpp interface used > for transfer > #include > > int main(int argc, char *argv[]) { > >try { >RInside R(argc, argv); // create an embedded R instance >SEXP ans; > >std::string txt = "suppressMessages(library(fPortfolio))"; >if (R.parseEvalQ(txt)) // load library, no return value >throw std::runtime_error("R cannot evaluate '" + txt + "'"); > >txt = "lppData <- 100 * LPP2005.RET[, 1:6]; " > "ewSpec <- portfolioSpec(); " > "nAssets <- ncol(lppData); "; >if (R.parseEval(txt, ans)) // prepare problem >throw std::runtime_error("R cannot evaluate '" + txt + "'"); > >const double dvec[6] = { 0.1, 0.1, 0.1, 0.1, 0.3, 0.3 }; // choose > any weights you want >const std::vector w(dvec, &dvec[6]); > >R.assign( w, "weightsvec"); // assign STL vector to R's > 'weightsvec' variable > >txt = "setWeights(ewSpec) <- weightsvec"; >if (R.parseEvalQ(txt)) // evaluate assignment >throw std::runtime_error("R cannot evaluate '" + txt + "'"); > >txt = "ewPortfolio <- feasiblePortfolio(data = lppData, spec = > ewSpec, constraints = \"LongOnly\"); " > "print(ewPortfolio); " > "vec <- getCovRiskBudgets(ewportfo...@portfolio)"; >if (R.parseEval(txt, ans)) // assign covRiskBudget weights to > ans >throw std::runtime_error("R cannot evaluate '" + txt + "'"); >RcppVector V(ans); // convert SEXP variable to an > RcppMatrix > >R.parseEval("names(vec)", ans); // assign columns names to ans >RcppStringVector names(ans); > >for (int i=0; i std::cout << std::setw(16) << names(i) << "\t" ><< std::setw(11) << V(i) << "\n"; >} > >} catch(std::exception& ex) { >std::cerr << "Exception caught: " << ex.what() << std::endl; >} catch(...) { >std::cerr << "Unknown exception caught" << std::endl; >} > >exit(0); > } > > > > -- > Three out of two people have difficulties with fractions. > [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] build issues on Solaris (PR#13975)
Full_Name: Rodney Sparapani Version: 2.9.2 OS: Solaris 10 Submission from: (NULL) (141.106.121.40) There are a few issues with building on Solaris (and UNIX in general, I suppose). 1. on line 50686 of configure, I'm seeing some trouble: lib=`echo ${lib}|sed -e s:${JAVA_HOME}:\$\{JAVA_HOME\}:g` Evidently, $lib contains colons which will confuse sed, so you can work around this like: lib=`echo ${lib}|sed -e s...@${java_home}@\$\{java_hom...@g` 2. in various Makefiles, FRONTFILES is blank which causes the error: syntax error at line 1 : `;' unexpected FRONTFILES is only necessary in one Makefile: src/library/stats/Makefile Therefore, adding the following in that file: .PHONY: frontfiles frontfiles: @for f in $(FRONTFILES); do \ if test -f $(srcdir)/$${f}; then \ $(INSTALL_DATA) $(srcdir)/$${f} \ $(top_builddir)/library/$(pkg); \ fi; \ done with the associated change of front to frontfiles a few lines above. And changing: share/make/basepkg.mk as follows: front: # @for f in $(FRONTFILES); do \ # if test -f $(srcdir)/$${f}; then \ # $(INSTALL_DATA) $(srcdir)/$${f} \ # $(top_builddir)/library/$(pkg); \ # fi; \ # done fixes that problem. 3. If you try to configure after a make distclean, I get the error: config.status: error: cannot find input file: etc/Makefile.in You can workaround this, by starting all over with a fresh unpacking of that tgzball. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel