Spotfire/TERR Issue - Error in parse(text = script)

466 Views Asked by At

Error in parse(text = script) : parse error in text argument: symbol ​​​​​​​ must be written using backticks (line 26, characters 47 through 67)

I get the above errors when I try using the below code. Weird thing is that I don't have any `` in my code.. Any suggestions for what I am missing? Line 26 starts with if(sum(gdata..

data = data.frame( Well, Prod, ProdDate )

data$ProdDate = as.POSIXct(data$ProdDate, origin = "1970-01-01", tz="UTC")
data$ProdDate <- interpNA(data$ProdDate, method = c("linear") 
minDate = aggregate(x=data$ProdDate, by=list(data$Well), FUN=min)
colnames(minDate) <- c("Well","MinDate")
data = merge(data, minDate, by="Well", all.x=TRUE)

# Calculate Days On
data$MinDate = as.POSIXct(data$MinDate, origin="1970-01-01", tz="UTC")
data$DaysOn = as.numeric(data$ProdDate - data$MinDate, units="days")
data$Predict = rep(NA, nrow(data))
data$Qi = rep(NA, nrow(data))
data$A = rep(NA, nrow(data))
data$B = rep(NA, nrow(data))

gdata <- data;

min.RSS <- function(data, par) {
  with(data, sum(((par[1]/((1+par[2]*par[3] * DaysOn)^(1/par[3]))) - Oil)^2))
}

wells = unique( na.omit(gdata$Well) )
 for(well in wells) {
    idx = gdata$Well == well
    if(sum(gdata$Prod[idx], na.rm=TRUE) > 0) {​​​​​​​
        startQi = max(data$Prod[idx], na.rm=TRUE)
        fit <- optim(par = c(startQi, .2), min.RSS, x = gdata[idx,])
        gdata$Predict[idx] = fit$par[1]/((1+fit$par[2]*1*gdata$DaysOn[idx])^(1/1))
        gdata$Qi[idx] = fit$par[1]
        gdata$A[idx] = fit$par[2]
        gdata$B[idx] = 1 
    }​​​​​​​
}​​​​​​​
gdata$ProdDateCheck <- gdata$ProdDate
Predict <- gdata #gdata[, c("MinDate", "DaysOn", "Predict", "Qi", "A", "B")]

1

There are 1 best solutions below

6
On

You have a bunch of zero-length space characters (Unicode 200B) after the opening brace on line 26. You can't see them because they are invisible.

You can confirm this if you copy the code line directly into your R console. If you hit "edit" under your question, then copy line 26 into your clipboard, when you go into R and do:

readClipboard()

You'll get

#> [1] "    if(sum(gdata$Prod[idx], na.rm=TRUE) > 0) {???????"

Where you can see that the R interpreter doesn't know how to display the zero-length string characters. These are what are causing the error.

The easiest way to fix this is to go into the file, select the start of the next line then hit backspace until the brace is deleted. Write in a new brace and a line break, then save. Your file should work after that.

As for how they got there - it's possible that you got these if you copied the code from an html source, or maybe someone is playing a prank?