简体   繁体   中英

How can I send R code containing the % symbol to IBM dashDB?

I'm trying to send and execute an R script to the IBM dashDB REST endpoint based on the tutorial .

Everything works quite nice but when I use the following code

timestamp=as.numeric(strptime(df$TIMESTAMP, \"%Y-%m-%d %H:%M:%S.000000\"));

The dashDB REST service simply returns:

An internal error has occurred. Please check the URL and try again.

Using the R web console inside the dashDB service the script runs fine. I've attached the whole script at the end of this message.

Any ideas?

library(ibmdbR)
mycon <- idaConnect("BLUDB", "", "")
idaInit(mycon)

df <- as.data.frame(ida.data.frame('"DASH110683"."TEMPERATURE"')[ ,c('NAME', 'TEMPERATURE', 'TIMESTAMP')])

pattern="%Y-%m-%d %H:%M:%S.000000"

timestamp=as.numeric(strptime(df$TIMESTAMP, pattern))


maxTimestamp=max(timestamp)
cutOffTimestamp=maxTimestamp - 10
idx = which(timestamp>cutOffTimestamp)
workingSubset=df[idx,]

devideIds=unique(workingSubset$NAME)
scores = 1:length(devideIds)
for (i in 1:length(devideIds)) {
    idx = which(workingSubset$NAME==devideIds[i])
    df=workingSubset[idx,]
    values=as.numeric(df$TEMPERATURE)
    #scores[i]=(sqrt((globalMean- mean(values))^2) +sqrt((globalSD- sd(values))^2))/2
    #scores[i]=abs(globalSD- sd(values))
    scores[i]=sd(values)
}

if (max(scores)>1) {
  devideIdOutlier=devideIds[scores==max(scores)]
} else {
  devideIdOutlier=0;
}

Romeo, the API described in the tutorial is more of a preliminary one. In fact we have just made available the new strategic one that also provides more options. You can now either pass in the R script via a request parameter or you can reference a R script that is stored inside dashDB (eg by using the built-in RStudio and saving the script).

https://developer.ibm.com/clouddataservices/wp-content/themes/projectnext-clouddata/dashDB/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM