ropensci / fingertipsR

R package to interact with Public Health England’s Fingertips data tool
https://docs.ropensci.org/fingertipsR
92 stars 18 forks source link

FingertipsR - EXTREMELY elementary question (so apologies) #65

Open WizardAKA opened 5 years ago

WizardAKA commented 5 years ago

I'm trying to get some of basic functionality of FingertipsR to work e.g.

fingertips_stats()

But getting this error

Error: lexical error: invalid char in json text.

Trend Micro (right here) ------^ The fact I can't even use the most basic functions makes me think there's something wrong in the software or privleges. Could anyone help? </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/sebastian-fox"><img src="https://avatars.githubusercontent.com/u/26870222?v=4" />sebastian-fox</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>Could you paste in the output of typing <code>sessionInfo()</code> into your console please? It shouldn't need any extra privileges for that function to work.</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/WizardAKA"><img src="https://avatars.githubusercontent.com/u/47738936?v=4" />WizardAKA</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <blockquote> <p>sessionInfo() R version 3.5.2 (2018-12-20) Platform: i386-w64-mingw32/i386 (32-bit) Running under: Windows 7 (build 7601) Service Pack 1</p> </blockquote> <p>Matrix products: default</p> <p>locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252<br /> [3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C<br /> [5] LC_TIME=English_United Kingdom.1252 </p> <p>attached base packages: [1] stats graphics grDevices utils datasets methods base </p> <p>other attached packages: [1] fingertipscharts_0.0.4 fingertipsR_0.2.0 </p> <p>loaded via a namespace (and not attached): [1] geojsonio_0.6.0 jsonlite_1.6 magrittr_1.5 gtable_0.2.0 class_7.3-15<br /> [6] tidyr_0.8.2 hms_0.4.2 sp_1.3-1 stringr_1.4.0 pillar_1.3.1<br /> [11] htmltools_0.3.6 curl_3.3 later_0.8.0 dplyr_0.8.0.1 lattice_0.20-38<br /> [16] htmlwidgets_1.3 tidyselect_0.2.5 plyr_1.8.4 lemon_0.4.3 miniUI_0.1.1.1<br /> [21] maptools_0.9-5 knitr_1.21 gridExtra_2.3 V8_2.0 mime_0.6<br /> [26] pkgconfig_2.0.2 R6_2.4.0 shiny_1.2.0 digest_0.6.18 xfun_0.5<br /> [31] colorspace_1.4-0 shinycssloaders_0.2.0 DT_0.5 stringi_1.3.1 lazyeval_0.2.1<br /> [36] crosstalk_1.0.0 geojson_0.3.2 tibble_2.0.1 httr_1.4.0 compiler_3.5.2<br /> [41] xtable_1.8-3 munsell_0.5.0 DBI_1.0.0 jqr_1.1.0 Rcpp_1.0.0<br /> [46] rgdal_1.3-9 assertthat_0.2.0 readr_1.3.1 ggplot2_3.1.0 classInt_0.3-1<br /> [51] leaflet_2.0.2 tools_3.5.2 units_0.6-2 foreign_0.8-71 httpuv_1.4.5.1<br /> [56] e1071_1.7-0.1 scales_1.0.0 crayon_1.3.4 glue_1.3.0 purrr_0.3.0<br /> [61] rlang_0.3.1 promises_1.0.1 rgeos_0.4-2 sf_0.7-3 grid_3.5.2 </p> <blockquote> </blockquote> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/sebastian-fox"><img src="https://avatars.githubusercontent.com/u/26870222?v=4" />sebastian-fox</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>Hmmm, interesting. This is new to me and I'm not too sure how to get to the bottom of it. All of your package versions which <code>fingertipsR</code> depends on look ok .</p> <p>Could you try closing an opening RStudio, and then run the following before loading any other package?</p> <pre><code>fingertipsR::fingertips_stats()</code></pre> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/WizardAKA"><img src="https://avatars.githubusercontent.com/u/47738936?v=4" />WizardAKA</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>I get exactly the same error</p> <p>This may take a few moments... Error: lexical error: invalid char in json text.</p> <html><head><title>Trend Micro (right here) ------^ </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/sebastian-fox"><img src="https://avatars.githubusercontent.com/u/26870222?v=4" />sebastian-fox</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>Thanks - I'm struggling to reproduce this. Do you get the same error with the following?</p> <pre><code>df <- fingertipsR::indicators()</code></pre> <p>And what happens with the following?</p> <pre><code>df <- fingertipsR::fingertips_data(90366)</code></pre> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/WizardAKA"><img src="https://avatars.githubusercontent.com/u/47738936?v=4" />WizardAKA</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>Not sure if I can add screen grabs, but I get the same error for all.</p> <p>The reason I wanted to do the screen grab is because I wasn’t sure the </p> <p>(right here)-----^</p> <p>Pointing at the ‘h’ in html was showing.</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/WizardAKA"><img src="https://avatars.githubusercontent.com/u/47738936?v=4" />WizardAKA</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p><img src="https://user-images.githubusercontent.com/47738936/53488220-92d4ed00-3a85-11e9-9cda-4cff5edfd69f.png" alt="rgrab" /></p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/sebastian-fox"><img src="https://avatars.githubusercontent.com/u/26870222?v=4" />sebastian-fox</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>Thank you. Does this url work in your browser? <a href="https://fingertips.phe.org.uk/api/all_data/csv/by_indicator_id?indicator_ids=90366&child_area_type_id=102&parent_area_type_id=6&include_sortable_time_periods=yes">https://fingertips.phe.org.uk/api/all_data/csv/by_indicator_id?indicator_ids=90366&child_area_type_id=102&parent_area_type_id=6&include_sortable_time_periods=yes</a></p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/WizardAKA"><img src="https://avatars.githubusercontent.com/u/47738936?v=4" />WizardAKA</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>Hi Sebastian, yes, at least I think so. It brings up a page with what looks like comma delimited data for whole bunch of indicators broken down by deprivation decile, geography etc.</p> <p>And that's in Chrome. In IE it prompts to save a file with suffix ".json" which I sort of understand is a file type.</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/sebastian-fox"><img src="https://avatars.githubusercontent.com/u/26870222?v=4" />sebastian-fox</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>Ok, we might be getting close now...but we may not!</p> <p>Can you try the following:</p> <pre><code>library(dplyr) library(httr) library(curl) dataurl <- "https://fingertips.phe.org.uk/api/all_data/csv/by_indicator_id?indicator_ids=90366&child_area_type_id=102&parent_area_type_id=6&include_sortable_time_periods=yes" df_string <- dataurl %>% GET(use_proxy(ie_get_proxy_for_url(.), username = "", password = "", auth = "ntlm")) %>% content("text") new_data <- read.delim(text = df_string, encoding = "UTF-8", sep = ",", fill = TRUE, header = TRUE, stringsAsFactors = FALSE, check.names = FALSE) </code></pre> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/WizardAKA"><img src="https://avatars.githubusercontent.com/u/47738936?v=4" />WizardAKA</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <h2>This is what I'm getting</h2> <pre><code>> library(dplyr) Attaching package: ‘dplyr’ The following objects are masked from ‘package:stats’: filter, lag The following objects are masked from ‘package:base’: intersect, setdiff, setequal, union > library(httr) > library(curl) Attaching package: ‘curl’ The following object is masked from ‘package:httr’: handle_reset > dataurl <- "https://fingertips.phe.org.uk/api/all_data/csv/by_indicator_id?indicator_ids=90366&child_area_type_id=102&parent_area_type_id=6&include_sortable_time_periods=yes" > df_string <- dataurl %>% + GET(use_proxy(ie_get_proxy_for_url(.), username = "", password = "", auth = "ntlm")) %>% + content("text") > new_data <- read.delim(text = df_string, + encoding = "UTF-8", + sep = ",", + fill = TRUE, + header = TRUE, + stringsAsFactors = FALSE, + check.names = FALSE) Error in read.table(file = file, header = header, sep = sep, quote = quote, : more columns than column names</code></pre> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/WizardAKA"><img src="https://avatars.githubusercontent.com/u/47738936?v=4" />WizardAKA</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p><img src="https://user-images.githubusercontent.com/47738936/53489081-12fc5200-3a88-11e9-9c8d-ad9f3a504878.png" alt="rgrab2" /></p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/sebastian-fox"><img src="https://avatars.githubusercontent.com/u/26870222?v=4" />sebastian-fox</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>Huge can of worms! I don't suppose any of your colleagues have the same issue?</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/WizardAKA"><img src="https://avatars.githubusercontent.com/u/47738936?v=4" />WizardAKA</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>I'm literally the first person to use R in my organisation. </p> <p>I did wonder if it was something to do with access privileges, or the way web access is configured. I don't know if a firewall or anything would effect this. </p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/sebastian-fox"><img src="https://avatars.githubusercontent.com/u/26870222?v=4" />sebastian-fox</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>Hi @WizardAKA - I'm still very confused by this. Could you try running this (this is very similar to the previous chunk of code but not identical):</p> <pre><code>library(dplyr) library(httr) library(curl) dataurl <- "https://fingertips.phe.org.uk/api/all_data/csv/by_indicator_id?indicator_ids=90366&child_area_type_id=102&parent_area_type_id=6&include_sortable_time_periods=yes&timestamp=12345929319412" df_string <- dataurl %>% GET(use_proxy(ie_get_proxy_for_url(.), username = "", password = "", auth = "ntlm")) %>% content("text") new_data <- read.delim(text = df_string, encoding = "UTF-8", sep = ",", fill = TRUE, header = TRUE, stringsAsFactors = FALSE, check.names = FALSE)</code></pre> <p>Thank you</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/WizardAKA"><img src="https://avatars.githubusercontent.com/u/47738936?v=4" />WizardAKA</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>Hi Sebastian,</p> <p>Here's what I get -</p> <pre><code>> library(dplyr) > library(httr) > library(curl) > dataurl <- "https://fingertips.phe.org.uk/api/all_data/csv/by_indicator_id?indicator_ids=90366&child_area_type_id=102&parent_area_type_id=6&include_sortable_time_periods=yes&timestamp=12345929319412" > df_string <- dataurl %>% + GET(use_proxy(ie_get_proxy_for_url(.), username = "", password = "", auth = "ntlm")) %>% + content("text") > new_data <- read.delim(text = df_string, + encoding = "UTF-8", + sep = ",", + fill = TRUE, + header = TRUE, + stringsAsFactors = FALSE, + check.names = FALSE) Error in read.table(file = file, header = header, sep = sep, quote = quote, : more columns than column names</code></pre> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/WizardAKA"><img src="https://avatars.githubusercontent.com/u/47738936?v=4" />WizardAKA</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>The error is </p> <p>Error in read.table(file = file, header = header, sep = sep, quote = quote, : more columns than column names</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/sebastian-fox"><img src="https://avatars.githubusercontent.com/u/26870222?v=4" />sebastian-fox</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>Thank you. Ok - I don't understand this error, but I can now replicate your original error. I'll get back to you about that soon hopefully, and then see what we can do about this one!</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/WizardAKA"><img src="https://avatars.githubusercontent.com/u/47738936?v=4" />WizardAKA</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>Thanks Sebastian, really kind and appreciate the effort!</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/sebastian-fox"><img src="https://avatars.githubusercontent.com/u/26870222?v=4" />sebastian-fox</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>No problem. But I'm confused again!</p> <p>Could you try this, which I think will fail with the same error you were originally getting:</p> <pre><code>library(dplyr) library(httr) library(curl) library(jsonlite) api_path <- "https://fingertips.phe.org.uk/api/area_types/parent_area_types" df <- api_path %>% GET(use_proxy(ie_get_proxy_for_url(.), username = "", password = "", auth = "ntlm")) %>% content("text") %>% fromJSON(flatten = TRUE)</code></pre> <p>If that fails, could you run this, which I think will pass.</p> <pre><code>library(dplyr) library(httr) library(curl) library(jsonlite) api_path <- "https://fingertips.phe.org.uk/api/area_types/parent_area_types" df <- api_path %>% GET(use_proxy(ie_get_proxy_for_url(.), username = "", password = "", auth = "ntlm")) %>% content("text", encoding = "UTF-8") write.table(df, file = "df.txt", sep = "")</code></pre> <p>If all goes well, the last line will write a file called <code>df.txt</code> to your working directory. Could you attach it to this discussion? (it contains the html that you are trying to read - it shouldn't contain any personal info, but if you don't feel comfortable you can email it to me at sebastian.fox@phe.gov.uk)</p> <p>Thank you</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/WizardAKA"><img src="https://avatars.githubusercontent.com/u/47738936?v=4" />WizardAKA</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>The first script leads to the same error as you anticipated -</p> <p>Error: lexical error: invalid char in json text.</p> <html><head><title>Trend Micro (right here) ------^ The second file did pass - I will send it to you because I don't understand fully what it is. Thanks. </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/sebastian-fox"><img src="https://avatars.githubusercontent.com/u/26870222?v=4" />sebastian-fox</a> commented <strong> 5 years ago</strong> </div> <div class="markdown-body"> <p>Super - thank you. I will respond by email but I think the issue is to do with your organisation's ransomware scanner.</p> </div> </div> <div class="page-bar-simple"> </div> <div class="footer"> <ul class="body"> <li>© <script> document.write(new Date().getFullYear()) </script> Githubissues.</li> <li>Githubissues is a development platform for aggregating issues.</li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/githubissues/assets/js.js"></script> <script src="/githubissues/assets/markdown.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/go.min.js"></script> <script> hljs.highlightAll(); </script> </body> </html>