Hi all.
I'm having a little trouble with the  function "texteval" (session package).
I have used "texteval" in the construction of the function "ExpandData1".
"ExpandData1" does not work as expected. However, when I run only the inside 
code
of "ExpandData1" I get the right result. Apparently "texteval" is not working 
when
used called by another function. Here is a simple example:
> library(session)
> library(compositions)
The following object(s) are masked from 'package:robustbase': 
> ExpandData1 <- function(Data,linkFunctionsVector,numPar)
+ {
+   attach(as.data.frame(Data))
+   EvalData = array(0, c(nrow(Data),length(linkFunctionsVector) ) )
+   for(idexpr in 1: length(linkFunctionsVector)) {
+   if(linkFunctionsVector[idexpr] == "1"){ EvalData[,idexpr] = 
rep(1,nrow(Data))} 
+   else{  texteval(paste("EvalData[,idexpr] =", linkFunctionsVector[idexpr]), 
echo = TRUE)}
+   }
+   
+   ExpData = NULL
+   for(idpar in 1: numPar){
+   ExpData = cbind(ExpData, EvalData)
+   }
+   colnames(ExpData) = rep(linkFunctionsVector,numPar)
+   return(ExpData)
+ }
> 
> # defining the parameters "Data", "linkFunctionsVector",  and "numPar"
> 
> numPar = 2
> linkFunctionsVector = c("1", "depth", "depth^2")
> data(ArcticLake)
> 
> A = ArcticLake[1:5,]
> Data = array(A[,4],c(5,1))
> colnames(Data) = c("depth")
> 
> # calling the function
> 
> ExpandData1(Data,linkFunctionsVector,numPar)
The following object(s) are masked from 'as.data.frame(Data) (position 11)':
    depth
     1 depth depth^2 1 depth depth^2
[1,] 1     0       0 1     0       0
[2,] 1     0       0 1     0       0
[3,] 1     0       0 1     0       0
[4,] 1     0       0 1     0       0
[5,] 1     0       0 1     0       0
> 
> # however, running only the inside code
> 
> attach(as.data.frame(Data))
>   EvalData = array(0, c(nrow(Data),length(linkFunctionsVector) ) )
>   for(idexpr in 1: length(linkFunctionsVector)) {
+   if(linkFunctionsVector[idexpr] == "1"){ EvalData[,idexpr] = 
rep(1,nrow(Data))} 
+   else{  texteval(paste("EvalData[,idexpr] =", linkFunctionsVector[idexpr]), 
echo = TRUE)}
+   }
>   
>   ExpData = NULL
>   for(idpar in 1: numPar){
+   ExpData = cbind(ExpData, EvalData)
+   }
>   colnames(ExpData) = rep(linkFunctionsVector,numPar)
>  
> # I get the right result
> 
> ExpData
     1 depth depth^2 1 depth depth^2
[1,] 1  10.4  108.16 1  10.4  108.16
[2,] 1  11.7  136.89 1  11.7  136.89
[3,] 1  12.8  163.84 1  12.8  163.84
[4,] 1  13.0  169.00 1  13.0  169.00
[5,] 1  15.7  246.49 1  15.7  246.49
> 
I have no idea why this is happening. Any idea?



      
        [[alternative HTML version deleted]]

______________________________________________
[email protected] 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.

Reply via email to