Reputation: 26248
Some versions of RStudio throw an error in the Viewer pane of my javascript widget, and some don't.
I've created a htmlwidget for my googleway
package that plots a Google Map.
To reproduce this issue (if indeed it is an issue on your system) you can simply run this code
devtools::install_github("SymbolixAU/googleway")
library(googleway)
google_map(key = '') ## you don't need a key to see the error
But if you want to view a map, you'll need a Google Maps API key
The issue I'm having is that on some versions of Rstudio the map shows in the Viewer pane, and in others it doesn't.
When I "inspect" the Viewer (right-click > inspect > console), I get the error
SyntaxError: Unexpected identifier 'i'. Expected either 'in' or 'of' in enumeration syntax.
Which links to a for
loop inside the javascript (see screenshot and the source code)
This morning I upgraded Rstudio on the system that caused the error, but it's still giving the error.
The following two screenshots show two different Macs (both running OS Sierra) with Rstudio, with examples of
Why does some versions of RStudio throw the error, and some don't?
Upvotes: 3
Views: 479
Reputation: 26248
@timelyportfolio's suggestion was instrumental (again!) in finding the solution.
I'm not convinced the issue was purely due to Rstudio, or there are other factors involved, especially as the widget works on an older version, but for now I'll leave this as the solution.
The let
in the line
for (let i = 0; i < data.calls.length; i++) {
is not supported in all browsers, so changing it to var
worked for that line (and all the lines that use a let
).
I was also using this method for finding values in an array
data_.find(x => x.id === _id)
Which again is not supported in all browsers, so reverting to
function findById(source, id) {
for (var i = 0; i < source.length; i++) {
if (source[i].id === id) {
return source[i];
}
}
return;
}
seems to resolve that issue too.
et voila!
Upvotes: 4