ColinFay / hordes

R from NodeJS, the right way.
https://colinfay.me/hordes/
58 stars 8 forks source link

Data exchange #12

Open fmmattioni opened 3 years ago

fmmattioni commented 3 years ago

Hi Colin!

I believe this issue is not related to hordes, but I have no idea what could be the root of the issue at this point.

API reprex: https://github.com/fmmattioni/hordes-reprex

R package to reproduce the issue: https://github.com/fmmattioni/reprexhordes

The issue:

Cannot return the output of a function after a call to readxl::readl_excel().

And it throws the following error:

in JSON at position 2d token
    at JSON.parse (<anonymous>)
    at /Users/fmattioni/hordes-reprex/src/api/iris.js:23:19
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Thanks in advance! Felipe

fmmattioni commented 3 years ago

Interestingly, if I remove JSON.parse(), I can see that calling the function that reads the excel file, this is added at the beginning of the output:

\r-\r/\r \r

which makes JSON.parse() fail.

fmmattioni commented 3 years ago

Issue can be fixed by adding the following:

const output = await reprexhordes.return_iris_excel();
const regExp = /\[([^)]+)\]/;
const matches = regExp.exec(output)[0];

But it is really intriguing on why this happens...