problem with .get_curl #26

Closed
restonslacker opened this Issue Jun 17, 2015 · 8 comments

Projects

None yet

2 participants

@restonslacker
Contributor

when trying to use pbPost() i get the following error:
Error in if (curl == "") stop(paste("No curl binary registered. ", "Install curl, and restart R and reload package")

however, curl is installed and running Sys.which("curl") returns

> Sys.which("curl")
           curl 
"/usr/bin/curl" 

I'm running R 3.2.0 on Redhat.

@eddelbuettel
Owner

Please debug locally. There is nothing I can do for you here without a minimally reproducible example as I too have curl in /usr/bin/ and that works just fine and has since day one ...

One idea would be to compare what /bin/sh points to, or to inquire why the test in the first statement of .onAttach() fails:

curl <- Sys.which("curl")
@restonslacker
Contributor

Ahh! i think I've found some insight into the issue. The following block works (or should once i solve the CA cert issue):

library("RPushbullet")
pbPost("note","test","test test", email="me@mydomain.org", apikey="<my very very secret key>")

However, I was taking a shortcut:

RPushbullet::pbPost("note","test","test test", email="me@mydomain.org", apikey="<my very very secret key>")

In this case, .pkgenv has never been initialized. This explains why the test for curl<- Sys.which("curl") seemed to pass (it was never getting called) but the test in .getCurl fails (because the value for curl was never set so of course the value for .pkgenv$curl is empty).

Perhaps adding an additional check in .getcurl() either to see if the package is loaded or something like

if(curl=="" && (curl <- Sys.which("curl"))==""){
   stop("...")
}

would work?

@eddelbuettel
Owner

Fair point. I'll make that change. And/or check if the package was never attached, or change the logic to maybe call '.initialize()` in that case.

@restonslacker
Contributor

what about:

pbPost <- function(<snip>){
  if (! ("RPushbullet" %in% loadedNamespaces()){
    RPushbullet:::.parseResourceFile()
  }
...
}

strictly speaking, this is unnecessary if the call to pbPost() has an email= specified as the destination (after #30), but if someone tries to use recipients= it will fail without a block like this one.

@eddelbuettel
Owner

From the looks that was a dance around sourcing the config file when the package was not attached.

Do you feel strongly about removing it? Should not do too much damage.

@restonslacker
Contributor

I have not committed this block of code yet. Thinking about it a bit more, I'm okay if we don't use it and close this issue. As it stands now with #30, a call to RPushbullet::pbPost() will work if email= or channel= is specified, but not if recipients= is specified. This makes some sense as generally recipients= will be a number or a device name which are indexes or keys into a list. It is probably better to require the package to be loaded in that case.

@eddelbuettel
Owner

I have that issue with other packages too. Stateful data in a per-package environment requires .onAttach() which requires loading the package. It may be possible to farm the work out into a helper function called from both .onLoad() and .onAttach(). That way direct use via :: without loading should work.

But then again these are hairsplitting decisions. Let's get the bigger things right first and use the curl package. We can then see what is happening...

@eddelbuettel
Owner

I think I now now know what do to (thanks for some hints from an R Core member reviewing a paper draft having similar code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment