I have been working with spotfire and realized that my python codes edit the column properties much faster than the r codes. The r code takes about 24 seconds, while the python code takes about 4 to do the same thing. Is my r code just written poorly that it makes this happen.
Here is an example of my python code:
start=time.time()
count=0
names=[]
for i in olddt.Columns: #getting columns from old data table
names.append(i)
for i in dt.Columns: #assigning new values
if count<=4:
i.Properties["Limits.Whatif.Upper"]=1.0
i.Properties["Limits.Whatif.Lower"]=1.0
i.Properties["Limits.Prod.Upper"]=1.0
i.Properties["Limits.Prod.Lower"]=1.0
count=count+1
else:
i.Properties["Limits.Whatif.Upper"]=float(count-4)+26.0
i.Properties["Limits.Whatif.Lower"]=float(count-4)-39.0
i.Properties["Limits.Prod.Upper"]=names[count-4].Properties["Limits.Whatif.Upper"]+5.0
i.Properties["Limits.Prod.Lower"]=names[count-4].Properties["Limits.Whatif.Lower"]-4.0
count=count+1
print time.time()-start
Here is my R code:
for(col in 1:ncol(temp2)){
if (col<=4){
attributes(temp2[,col])$SpotfireColumnMetaData$upper=Inf
attributes(temp2[,col])$SpotfireColumnMetaData$lower=-1*Inf
attributes(temp2[,col])$SpotfireColumnMetaData$upper2=Inf
attributes(temp2[,col])$SpotfireColumnMetaData$lower2=-1*Inf
}
else{
names(attributes(dt[,col-4])$SpotfireColumnMetaData)<- lapply( names( attributes(dt[ ,col-4] )$SpotfireColumnMetaData), tolower)
attributes(temp2[,col])$SpotfireColumnMetaData$upper=2
attributes(temp2[,col])$SpotfireColumnMetaDatalower=1
attributes(temp2[,col])$SpotfireColumnMetaData$upper2=attributes(dt[,col-4])$SpotfireColumnMetaData$upper
attributes(temp2[,col])$SpotfireColumnMetaData$lower2=attributes(dt[,col-4])$SpotfireColumnMetaData$lower
}
}
I also used an lapply function seen here:
applyLimits <- function(col){
if (count<4){
attributes(temp2[,col])$SpotfireColumnMetaData$upper<<-Inf
attributes(temp2[,col])$SpotfireColumnMetaData$lower<<- (-1*Inf)
attributes(temp2[,col])$SpotfireColumnMetaData$upper2<<-Inf
attributes(temp2[,col])$SpotfireColumnMetaData$lower2<<- (-1*Inf)
count<<-count+1
}
else{
attributes(temp2[,col])$SpotfireColumnMetaData$upper<<-2
attributes(temp2[,col])$SpotfireColumnMetaData$lower<<-1
attributes(temp2[,col])$SpotfireColumnMetaData$upper2<<-attributes(dt[,col-4])$SpotfireColumnMetaData$upper2
attributes(temp2[,col])$SpotfireColumnMetaData$lower2<<-attributes(dt[,col-4])$SpotfireColumnMetaData$lower2
count<<-count+1
}
}
lapply(1:ncol(temp),applyLimits)
If there is some way to improve my r code please tell me, but I haven't seen a better way of adjust the properties of it. According to some research I have done temp2 and dt both should be data.frame