Quantcast
Channel: R.NET
Viewing all articles
Browse latest Browse all 1634

Commented Issue: R comment state does not persist to the end of a line [165]

$
0
0
In RGui, if I enter the following command, I get the response indicated:

```
> cat("Hello!\n"); #cat("Glad to see you today.\n"); cat("Goodbye.\n")
Hello!
```

However, if I pass this same line to `_engine.Evaluate()`, I get this response:

```
_engine.Evaluate("cat(\"Hello!\\n\"); #cat(\"Glad to see you today.\\n\"); cat(\"Goodbye.\\n\")");
----
Hello!
Goodbye.
```

Somehow R.NET apparently terminated the comment state at the semicolon and then evaluated the third `cat()` call. (Catcall... huh! I didn't plan that.)

According to http://cran.r-project.org/doc/manuals/r-release/R-lang.html#Comments, the hashmark should comment-out everything to the end of the line. This bug in R.NET prevents you from being able to use semicolons in pure text comments...

```
#-----------------------------------------------
# Read a text timestamp of the form "yyyy-mm-ddThh:mm:ss.xxx",
# where xxx=milliseconds. Returns a numeric value of the seconds
# since Jan 1 1970, with millisecond precision (i.e. 3 decimal places).
# I don't really have a reason to; but I'll use a semicolon.
#
readTimestamp = function (tstamp) {
as.numeric(strptime(tstamp,format='%Y-%m-%dT%H:%M:%S.')) +
as.numeric(substr(tstamp,20,23))
}
Status Error for but I'll use a semicolon.
: unexpected symbol
```

...but it also violates the principle of least astonishment in possibly (dangerously!) subtle ways:

```
if (badthing == TRUE) {
# Reset several variables to a safe state
a = 23; b = 24; c = 25 # these are safer than the original values (below, commented out)
#a = 33; b = 34; c = 35
}
cat(a,b,c)
----
23 34 35
```


Comments: Sure, no prob.... thanks for fixing it so quickly. And thanks very very much for R.NET in general, it's a lifesaver!

Viewing all articles
Browse latest Browse all 1634

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>