See this notebook: Trouble with fetch / Ryan Govostes / Observable
I can fetch a CSV file in one cell, and then parse it in another. But if I try to fetch and parse in a single cell, I get an error:
TypeError: t.charCodeAt is not a function. (In 't.charCodeAt(s-1)', 't.charCodeAt' is undefined)
This seems to violate the concept that a variable’s value and its name are interchangeable. What is happening here?
Here’s a suggestion: Comparing ‘Trouble with fetch’ by Ryan Govostes to ‘Trouble with fetch’ by Alex Garcia
.text() returns a Promise, so you have to
await it before passing it into
.csvParse(). But that makes 2
await statements in one line, which is a little hard to read, so there’s two other ways shown in the notebook that use
.then() instead. They all work the same, it’s just a difference in code readability!
Also, might as well mention: If this was instead a FileAttachment instead of a file on Github, you would be able to have
FileAttachment("file.csv").csv() all in one line! But since you’re fetching from a file on Github, then the
.csv() method isn’t available.
Thanks! I wonder why
.text() returns a Promise? My data unfortunately exceeds the 15 MB limit for a FileAttachment.
.text() Promise behavior comes from fetch’s
Body.text()! Same thing with