httr::content without message

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

httr::content without message

Roy Mendelssohn - NOAA Federal
Hi All:

I am using httr to download files form a service, in this case a .csv file.  When I use httr::content on the result,  I get a message.  Since this will be in a package.  I want to suppress the message,  but haven't figured out how to do so.

The following should reproduce the result:

myURL <- 'https://coastwatch.pfeg.noaa.gov/erddap/griddap/erdMH1sstdmday.csvp?time[0:1:last]'
r1 <- httr::GET(myURL)
junk <- httr::content(r1)

when the last command is run, you get:

Parsed with column specification:
cols(
  `time (UTC)` = col_datetime(format = "")
)

I want to suppress that output.

Thanks,

-Roy

**********************
"The contents of this message do not reflect any position of the U.S. Government or NOAA."
**********************
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
***Note new street address***
110 McAllister Way
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: [hidden email] www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected"
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: httr::content without message

David Winsemius

> On Jan 2, 2018, at 9:30 AM, Roy Mendelssohn - NOAA Federal <[hidden email]> wrote:
>
> Hi All:
>
> I am using httr to download files form a service, in this case a .csv file.  When I use httr::content on the result,  I get a message.  Since this will be in a package.  I want to suppress the message,  but haven't figured out how to do so.
>
> The following should reproduce the result:
>
> myURL <- 'https://coastwatch.pfeg.noaa.gov/erddap/griddap/erdMH1sstdmday.csvp?time[0:1:last]'
> r1 <- httr::GET(myURL)
> junk <- httr::content(r1)

Instead try:

junk <- suppressMessages(httr::content(r1))

>

> when the last command is run, you get:
>
> Parsed with column specification:
> cols(
>  `time (UTC)` = col_datetime(format = "")
> )
>
> I want to suppress that output.
>
> Thanks,
>
> -Roy
>
> **********************
> "The contents of this message do not reflect any position of the U.S. Government or NOAA."
> **********************
> Roy Mendelssohn
> Supervisory Operations Research Analyst
> NOAA/NMFS
> Environmental Research Division
> Southwest Fisheries Science Center
> ***Note new street address***
> 110 McAllister Way
> Santa Cruz, CA 95060
> Phone: (831)-420-3666
> Fax: (831) 420-3980
> e-mail: [hidden email] www: http://www.pfeg.noaa.gov/
>
> "Old age and treachery will overcome youth and skill."
> "From those who have been given much, much will be expected"
> "the arc of the moral universe is long, but it bends toward justice" -MLK Jr.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: httr::content without message

Ben Tupper-2
In reply to this post by Roy Mendelssohn - NOAA Federal
Ahoy!

That's a message generated by the readr::read_table() function (or it's friends).  You can suppress it a number of ways, but this should work as httr::content() will pass through arguments, like col_types = cols(), to the file reader.

junk <- httr::content(r1, col_types = cols())

See more here...

https://blog.rstudio.com/2016/08/05/readr-1-0-0/ <https://blog.rstudio.com/2016/08/05/readr-1-0-0/>


Cheers,
Ben



> On Jan 2, 2018, at 12:30 PM, Roy Mendelssohn - NOAA Federal <[hidden email]> wrote:
>
> Hi All:
>
> I am using httr to download files form a service, in this case a .csv file.  When I use httr::content on the result,  I get a message.  Since this will be in a package.  I want to suppress the message,  but haven't figured out how to do so.
>
> The following should reproduce the result:
>
> myURL <- 'https://coastwatch.pfeg.noaa.gov/erddap/griddap/erdMH1sstdmday.csvp?time[0:1:last]'
> r1 <- httr::GET(myURL)
> junk <- httr::content(r1)
>
> when the last command is run, you get:
>
> Parsed with column specification:
> cols(
>  `time (UTC)` = col_datetime(format = "")
> )
>
> I want to suppress that output.
>
> Thanks,
>
> -Roy
>
> **********************
> "The contents of this message do not reflect any position of the U.S. Government or NOAA."
> **********************
> Roy Mendelssohn
> Supervisory Operations Research Analyst
> NOAA/NMFS
> Environmental Research Division
> Southwest Fisheries Science Center
> ***Note new street address***
> 110 McAllister Way
> Santa Cruz, CA 95060
> Phone: (831)-420-3666
> Fax: (831) 420-3980
> e-mail: [hidden email] www: http://www.pfeg.noaa.gov/
>
> "Old age and treachery will overcome youth and skill."
> "From those who have been given much, much will be expected"
> "the arc of the moral universe is long, but it bends toward justice" -MLK Jr.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecocast Reports: http://seascapemodeling.org/ecocast.html
Tick Reports: https://report.bigelow.org/tick/
Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/




        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: httr::content without message

R help mailing list-2
In reply to this post by Roy Mendelssohn - NOAA Federal
You can suppress all messages from that command with
    junk <- suppressMessages(httr::content(r1))

If you only want to suppress that specific message you can use
withCallingHandlers:
    junk <- withCallingHandlers(
        httr::content(r1),
        message=function(e){
            if (grepl("Parsed with column specification",
conditionMessage(e))) {
               invokeRestart("muffleMessage")
            }
         }
      )


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Tue, Jan 2, 2018 at 9:30 AM, Roy Mendelssohn - NOAA Federal <
[hidden email]> wrote:

> Hi All:
>
> I am using httr to download files form a service, in this case a .csv
> file.  When I use httr::content on the result,  I get a message.  Since
> this will be in a package.  I want to suppress the message,  but haven't
> figured out how to do so.
>
> The following should reproduce the result:
>
> myURL <- 'https://coastwatch.pfeg.noaa.gov/erddap/griddap/
> erdMH1sstdmday.csvp?time[0:1:last]'
> r1 <- httr::GET(myURL)
> junk <- httr::content(r1)
>
> when the last command is run, you get:
>
> Parsed with column specification:
> cols(
>   `time (UTC)` = col_datetime(format = "")
> )
>
> I want to suppress that output.
>
> Thanks,
>
> -Roy
>
> **********************
> "The contents of this message do not reflect any position of the U.S.
> Government or NOAA."
> **********************
> Roy Mendelssohn
> Supervisory Operations Research Analyst
> NOAA/NMFS
> Environmental Research Division
> Southwest Fisheries Science Center
> ***Note new street address***
> 110 McAllister Way
> Santa Cruz, CA 95060
> Phone: (831)-420-3666
> Fax: (831) 420-3980
> e-mail: [hidden email] www: http://www.pfeg.noaa.gov/
>
> "Old age and treachery will overcome youth and skill."
> "From those who have been given much, much will be expected"
> "the arc of the moral universe is long, but it bends toward justice" -MLK
> Jr.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: httr::content without message

Roy Mendelssohn - NOAA Federal
In reply to this post by Ben Tupper-2
Thanks to all that replied.  I had just looked through the httr code and sure enough for a .csv mime time it calls readr::read_csv().  The httr::content docs suggest not using automatic parsing in a package,  rather to determine mime type and parse yourself and Ben's suggestion also works if I do:

junk <- readr::read_csv(r1$content, col_types = cols())

Perfect.  Using httr rather than putting the url in any of the read.csv or read_csv type code allows me greater control if the request fails.

Thanks again,

-Roy

> On Jan 2, 2018, at 9:44 AM, Ben Tupper <[hidden email]> wrote:
>
> Ahoy!
>
> That's a message generated by the readr::read_table() function (or it's friends).  You can suppress it a number of ways, but this should work as httr::content() will pass through arguments, like col_types = cols(), to the file reader.
>
> junk <- httr::content(r1, col_types = cols())
>
> See more here...
>
> https://blog.rstudio.com/2016/08/05/readr-1-0-0/
>
>
> Cheers,
> Ben
>
>
>
>> On Jan 2, 2018, at 12:30 PM, Roy Mendelssohn - NOAA Federal <[hidden email]> wrote:
>>
>> Hi All:
>>
>> I am using httr to download files form a service, in this case a .csv file.  When I use httr::content on the result,  I get a message.  Since this will be in a package.  I want to suppress the message,  but haven't figured out how to do so.
>>
>> The following should reproduce the result:
>>
>> myURL <- 'https://coastwatch.pfeg.noaa.gov/erddap/griddap/erdMH1sstdmday.csvp?time[0:1:last]'
>> r1 <- httr::GET(myURL)
>> junk <- httr::content(r1)
>>
>> when the last command is run, you get:
>>
>> Parsed with column specification:
>> cols(
>>  `time (UTC)` = col_datetime(format = "")
>> )
>>
>> I want to suppress that output.
>>
>> Thanks,
>>
>> -Roy
>>
>> **********************
>> "The contents of this message do not reflect any position of the U.S. Government or NOAA."
>> **********************
>> Roy Mendelssohn
>> Supervisory Operations Research Analyst
>> NOAA/NMFS
>> Environmental Research Division
>> Southwest Fisheries Science Center
>> ***Note new street address***
>> 110 McAllister Way
>> Santa Cruz, CA 95060
>> Phone: (831)-420-3666
>> Fax: (831) 420-3980
>> e-mail: [hidden email] www: http://www.pfeg.noaa.gov/
>>
>> "Old age and treachery will overcome youth and skill."
>> "From those who have been given much, much will be expected"
>> "the arc of the moral universe is long, but it bends toward justice" -MLK Jr.
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org
>
> Ecocast Reports: http://seascapemodeling.org/ecocast.html
> Tick Reports: https://report.bigelow.org/tick/
> Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/
>
>
>

**********************
"The contents of this message do not reflect any position of the U.S. Government or NOAA."
**********************
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
***Note new street address***
110 McAllister Way
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: [hidden email] www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected"
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: httr::content without message

Ben Tupper-2
That's good to know about when to auto-parse and when not to.  There is quite a big stable of tools to check the response before you try to read...

> httr::http_error(r1)
[1] FALSE

> httr::http_status(r1)
$category
[1] "Success"

$reason
[1] "OK"

$message
[1] "Success: (200) OK"

and

> httr::http_type(r1)
[1] "text/csv"


> On Jan 2, 2018, at 12:53 PM, Roy Mendelssohn - NOAA Federal <[hidden email]> wrote:
>
> Thanks to all that replied.  I had just looked through the httr code and sure enough for a .csv mime time it calls readr::read_csv().  The httr::content docs suggest not using automatic parsing in a package,  rather to determine mime type and parse yourself and Ben's suggestion also works if I do:
>
> junk <- readr::read_csv(r1$content, col_types = cols())
>
> Perfect.  Using httr rather than putting the url in any of the read.csv or read_csv type code allows me greater control if the request fails.
>
> Thanks again,
>
> -Roy
>
>> On Jan 2, 2018, at 9:44 AM, Ben Tupper <[hidden email]> wrote:
>>
>> Ahoy!
>>
>> That's a message generated by the readr::read_table() function (or it's friends).  You can suppress it a number of ways, but this should work as httr::content() will pass through arguments, like col_types = cols(), to the file reader.
>>
>> junk <- httr::content(r1, col_types = cols())
>>
>> See more here...
>>
>> https://blog.rstudio.com/2016/08/05/readr-1-0-0/
>>
>>
>> Cheers,
>> Ben
>>
>>
>>
>>> On Jan 2, 2018, at 12:30 PM, Roy Mendelssohn - NOAA Federal <[hidden email]> wrote:
>>>
>>> Hi All:
>>>
>>> I am using httr to download files form a service, in this case a .csv file.  When I use httr::content on the result,  I get a message.  Since this will be in a package.  I want to suppress the message,  but haven't figured out how to do so.
>>>
>>> The following should reproduce the result:
>>>
>>> myURL <- 'https://coastwatch.pfeg.noaa.gov/erddap/griddap/erdMH1sstdmday.csvp?time[0:1:last]'
>>> r1 <- httr::GET(myURL)
>>> junk <- httr::content(r1)
>>>
>>> when the last command is run, you get:
>>>
>>> Parsed with column specification:
>>> cols(
>>> `time (UTC)` = col_datetime(format = "")
>>> )
>>>
>>> I want to suppress that output.
>>>
>>> Thanks,
>>>
>>> -Roy
>>>
>>> **********************
>>> "The contents of this message do not reflect any position of the U.S. Government or NOAA."
>>> **********************
>>> Roy Mendelssohn
>>> Supervisory Operations Research Analyst
>>> NOAA/NMFS
>>> Environmental Research Division
>>> Southwest Fisheries Science Center
>>> ***Note new street address***
>>> 110 McAllister Way
>>> Santa Cruz, CA 95060
>>> Phone: (831)-420-3666
>>> Fax: (831) 420-3980
>>> e-mail: [hidden email] www: http://www.pfeg.noaa.gov/
>>>
>>> "Old age and treachery will overcome youth and skill."
>>> "From those who have been given much, much will be expected"
>>> "the arc of the moral universe is long, but it bends toward justice" -MLK Jr.
>>>
>>> ______________________________________________
>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> Ben Tupper
>> Bigelow Laboratory for Ocean Sciences
>> 60 Bigelow Drive, P.O. Box 380
>> East Boothbay, Maine 04544
>> http://www.bigelow.org
>>
>> Ecocast Reports: http://seascapemodeling.org/ecocast.html
>> Tick Reports: https://report.bigelow.org/tick/
>> Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/
>>
>>
>>
>
> **********************
> "The contents of this message do not reflect any position of the U.S. Government or NOAA."
> **********************
> Roy Mendelssohn
> Supervisory Operations Research Analyst
> NOAA/NMFS
> Environmental Research Division
> Southwest Fisheries Science Center
> ***Note new street address***
> 110 McAllister Way
> Santa Cruz, CA 95060
> Phone: (831)-420-3666
> Fax: (831) 420-3980
> e-mail: [hidden email] www: http://www.pfeg.noaa.gov/
>
> "Old age and treachery will overcome youth and skill."
> "From those who have been given much, much will be expected"
> "the arc of the moral universe is long, but it bends toward justice" -MLK Jr.
>

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecocast Reports: http://seascapemodeling.org/ecocast.html
Tick Reports: https://report.bigelow.org/tick/
Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/




        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.