ices-tools-prod / icesSD

R interface to Stock Database web services
http://sd.ices.dk/services/
GNU General Public License v2.0
1 stars 0 forks source link

Importing from package curl #1

Open colinpmillar opened 7 years ago

colinpmillar commented 7 years ago

So we have to explicitly import from curl, the functions that jsonlite::fromJSON uses.... Check out this poor behaviour! curl is not imported, but stated as a suggests, and the function contains a function loadpkg which tries to sneakily load the namespace! Why try so hard to avoid importing from the package??

loadpkg function(pkg){ tryCatch(getNamespace(pkg), error = function(e) { stop("Required package ", pkg, " not found. Please run: install.packages('", pkg, "')", call. = FALSE) }) }

jsonlite::fromJSON function (txt, simplifyVector = TRUE, simplifyDataFrame = simplifyVector, simplifyMatrix = simplifyVector, flatten = FALSE, ...) { if (!is.character(txt) && !is(txt, "connection")) { stop("Argument 'txt' must be a JSON string, URL or file.") } if (is.character(txt) && length(txt) == 1 && nchar(txt, type = "bytes") < 10000) { if (grepl("^https?://", txt, useBytes = TRUE)) { loadpkg("curl") h <- curl::new_handle(useragent = paste("jsonlite /", R.version.string)) curl::handle_setheaders(h, Accept = "application/json, text/*, */*") txt <- curl::curl(txt, handle = h) } else if (file.exists(txt)) { txt <- file(txt) } } fromJSON_string(txt = txt, simplifyVector = simplifyVector, simplifyDataFrame = simplifyDataFrame, simplifyMatrix = simplifyMatrix, flatten = flatten, ...) } <environment: namespace:jsonlite>

> packageDescription("jsonlite") Package: jsonlite Version: 1.0 Title: A Robust, High Performance JSON Parser and Generator for R License: MIT + file LICENSE NeedsCompilation: yes Depends: methods Author: Jeroen Ooms, Duncan Temple Lang, Lloyd Hilaiel URL: http://arxiv.org/abs/1403.2805, https://www.opencpu.org/posts/jsonlite-a-smarter-json-encoder BugReports: http://github.com/jeroenooms/jsonlite/issues Maintainer: Jeroen Ooms <jeroen.ooms@stat.ucla.edu> VignetteBuilder: knitr, R.rsp Description: A fast JSON parser and generator optimized for statistical data and the web. Started out as a fork of 'RJSONIO', but has been completely rewritten in recent versions. The package offers flexible, robust, high performance tools for working with JSON in R and is particularly powerful for building pipelines and interacting with a web API. The implementation is based on the mapping described in the vignette (Ooms, 2014). In addition to converting JSON data from/to R objects, 'jsonlite' contains functions to stream, validate, and prettify JSON data. The unit tests included with the package verify that all edge cases are encoded and decoded consistently for use with dynamic data in systems and applications. Suggests: httr, curl, plyr, testthat, knitr, rmarkdown, R.rsp RoxygenNote: 5.0.1 Packaged: 2016-06-30 23:02:54 UTC; jeroen Repository: CRAN Date/Publication: 2016-07-01 10:57:31 Built: R 3.3.1; x86_64-w64-mingw32; 2016-07-04 00:49:43 UTC; windows

colinpmillar commented 7 years ago

So we could use our old RCurl parser as we have for the other packages...

then call the fromJSON_string function.. this would avoid ever needing the curl package.. its is annoying if users of icesDatras and icesSLD had to install both RCurl and curl...

colinpmillar commented 7 years ago

Or we re-write all the packages to use curl, instead of RCurl [https://www.opencpu.org/posts/curl-release-0-2/]

slarge commented 7 years ago

My vote is for the most modern and actively developed... In this case curl? I can carve out some time after next week if we need to do some general maintenance and reworking if we decide to move that way. (Carve, that's a good function verb right there!!)

SL

On Sep 15, 2016, at 9:16 PM, Colin Millar notifications@github.com wrote:

Or we re-write all the packages to use curl, instead of RCurl [https://www.opencpu.org/posts/curl-release-0-2/]

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.