Geocode Error Zero Result in R - r

I'm currently using the google maps in R (I suppose it would be correct if I said I'm calling the google map API in R, is that right?).
Some of my address entries are not complete so the API returns an error. This is annoying because any valid addresses are not decoded after the error. Is there a way to skip the invalid addresses? Something like this:
Error in if (gc$status != "OK") { : argument is of length zero
In addition, it would be nice to have a message about the failing addresses. Something like:
Warning message: geocode failed with status ZERO_RESULTS, location = "XXX ST , SAN FRANCISC"
I'm using: loc1 <- geocode(as.character(TestAddress2$Address))

I discovered that the geocode call only returns warning for addresses it can't find. Thus the real problem was the fact that when there was no value for address it gave an error.
Thus I filtered out observations that did not have a value:
TestAddress2<- TestAddress2[!(TestAddress2$Address== " "),]

Related

libcurl function was given a bad argument CURLOPT_SSL_VERIFYHOST no longer supports 1 as value

While running the "PrepareAnnotationRefseq"  function from the customProDB package in R, I  ran into  a problem due to a compatibility issue of the curl version. I am currently using curl version 4.3.2.  The error report I got is:
PrepareAnnotationRefseq(genome='mm39',CDSfasta="geneseq.fasta",pepfasta="proteinseq.fasta", annotation_path, dbsnp = NULL, splice_matrix=FALSE, ClinVar=FALSE)
In curlSetOpt(..., .opts = .opts, curl = h, .encoding = .encoding) : Error setting the option for # 3 (status = 43) (enum = 81) (value = 0x55822c7f3b70): A libcurl function was given a bad argument CURLOPT_SSL_VERIFYHOST no longer supports 1 as value!
This could be a trivial problem for an expert in R, however with my current skill set I am unable to resolve this after looking for a solution on several forums and R groups. I would be very grateful if you could kindly shed some light on this issue. Perhaps a patch file that can fix the problem.
It's easy to read the manual. Why can't you do it?
If verify value is set to 1:
From 7.28.1 to 7.65.3: setting it to 1 made curl_easy_setopt() return an error and leaving the flag untouched.
Use 2.
When CURLOPT_SSL_VERIFYHOST is 2, that certificate must indicate that the server is the server to which you meant to connect, or the connection fails. Simply put, it means it has to have the same name in the certificate as is in the URL you operate against.
But why do you touch it? The default value for this option is 2 and is suitable for most cases of libcurl usage.

Is there a restriction on the no. of HERE API Calls I can make in a loop (using R)

I am trying to loop through a list of origin destination lat long locations to get the transit time. I am getting the following error when I loop. However when I do a single call (without looping), I get an output without error. I use the freemium HERE-API and I am allowed 250k transactions a month.
`for (i in 1:nrow(test))
{
call <- paste0("https://route.api.here.com/routing/7.2/calculateroute.json",
"?app_id=","appid",
"&app_code=","appcode",
"&waypoint0=geo!",y$dc_lat[i],",",y$dc_long[i],
"&waypoint1=geo!",y$store_lat[i],",",y$store_long[i],
"&mode=","fastest;truck;traffic:enabled",
"&trailerscount=","1",
"&routeattributes=","sh",
"&maneuverattributes=","di,sh",
"&limitedweight=","20")
response <-fromJSON(call, simplify = TRUE)
Traffic_time = (response[["response"]][["route"]][[1]][["summary"]][["trafficTime"]]) / 60
Base_time = (response[["response"]][["route"]][[1]][["summary"]][["baseTime"]]) / 60
print(Traffic_time)
}`
Error in file(con, "r"): cannot open the connection to 'https://route.api.here.com/routing/7.2/calculateroute.json?app_id=appid&app_code=appcode&waypoint0=geo!45.1005200,-93.2452000&waypoint1=geo!45.0978500,-95.0413620&mode=fastest;truck;traffic:enabled&trailerscount=1&routeattributes=sh&maneuverattributes=di,sh&limitedweight=20'
Traceback:
As per the error, this suggests that there is problem with the file at your end. it could be corrupt, good to try with changing the extension of the file. Can also try to restart your IDE. The number of API calls depend on the plans that you have opted for freemium or pro plans. You can have more details : https://developer.here.com/faqs

String causes geocode to throw error

running this line of code
library(ggmap)
geocode(location="Somewhere in Nigeria Winning",source="dsk", output="more")
throws this error
Error in vapply(gc$results[[1]]$address_components, function(x) x[[nameToGrab]], : values must be length 1, but FUN(X[[1]]) result is length 0
can someone shed some light on why this may be happening and what i can do to fix it? i know this seems like an odd question however this string showed up in a set of data to prune and seems to be breaking geocode.
just want to post an answer since i have located the problem, and anyone would like the workaround/want to know what to do. The issue is not with the DSK but with the ggmap code itself. If you run
geocode(location="not a place in the slightest",source="dsk", output="more")
then the library will fail gracefully and give you back the expected.
geocode failed with status ZERO_RESULTS, location = "not a place in the slightest"
however with certain strings in the middle like the one above it fails less gracefully because DSK returns data but it isn't good data the issue is caused by the data that sits here in the resulting array (note for obvious reasons you cant get this using the more flag you need to use all).
$results[[1]]$address_components[[1]]$long_name
NULL
$results[[1]]$address_components[[1]]$short_name
NULL
the code in the lib that parses this into the data frame with the "more" flag chokes here
nameToGrab <- `if`(nameType == "long", "long_name", "short_name")
outputVals <- vapply(gc$results[[1]]$address_components, function(x)
x[[nameToGrab]], character(1))
outputNames <- vapply(gc$results[[1]]$address_components, function(x){ if(length(x$types) == 0) return("query")
x$types[1]
},
character(1)
)
becasue both long_name and short_name are NULL the vapply is going to fail spectacularly.

Geocoding node-red-node-google. Error "Invalid request. Invalid 'latlng' parameter"

I´m not an expert in node-red and truly appreciate some help on using the node-red-node-google geocoding node.
link to Google Geolocation node-red node
I'm trying to obtain the location address via google Geolocation API from previously obtained coordinates using the node mentioned above (geocode by coordinates option). I take latitude and length via POST from an external application.
How should the latitude and longitude data be fed into the geocode node to get the correct address data? After tens of tests, I always obtain the same error: "Invalid request. Invalid 'latlng' parameter".
What I'm doing is:
Take data generated via POST http://my_public_ip:1880/geo?id={device}&time={time}&lat={lat}&lng={lng}&radius={radius}
The first node of the flow is a node-red Http In node, that implements the htp end-point, gets the info from that callback. Te info is retrieved correctly (see debug output) :
{"id":"18A834","time":"1503231980","lat":"40.xxxxxxxxxxxxxx","lng":"-3.xxxxxxxxxxxxxx","radius":"1651"}
Note: coordinates shadowed by privacy reasons.
If lng and lat values from the HTTP In node are fed into the Google Geocoding node, the message error "Invalid request. Invalid 'latlng' parameter" is received.
I fill the dialog box this way:
Latitude text box: msg.payload.lat
Longitude Text box:msg.payload.lng
I have tried several options inserting the coords function node:
convert the latitude and longitude values to float, keep only the first 7 decimals, convert again to strings ..., and always the same error is received: "Invalid request. Invalid 'latlng' parameter"
The coords function node configuration:
var coords ={};
latitude= parseFloat(msg.payload.lat).toFixed(7);
latitude1 = parseFloat(latitude);
var length = parseFloat(msg.payload.lng).toFixed(7);
var length1= parseFloat(length);
coords.payload = {lat:latitude1, lng:length1};
return coords;
The function output seems to be correct:
{"lat":40.xxxxxxx,"lng":-3.xxxxxxx}
So I expected to fill the text boxes with msg.payload.lat and msg.payload.lng should be ok. Clearly something is wrong ...
Does anybody know which is the correct way to feed longitude and latitude values to the node-red-node-google google-geocoding to get no errors?
Find below node-red used code (remember, also tested different types of variable and also tested with no function at all):
[{"id":"4dadb4d9.246a1c","type":"http in","z":"76138ea1.88752","name":"get_coords_from_post","url":"/geo","method":"get","upload":false,"swaggerDoc":"","x":300,"y":200,"wires":[["4a0b74fb.d10fcc","fb89b080.ef1cf","dac1b7ce.4cc2c8"]]},{"id":"fb89b080.ef1cf","type":"function","z":"76138ea1.88752","name":"coords","func":"var coords ={};\nlatitude= parseFloat(msg.payload.lat).toFixed(7);\nlatitude1 = parseFloat(latitude);\nvar length = parseFloat(msg.payload.lng).toFixed(7);\nvar length1= parseFloat(length);\ncoords.payload = {lat:latitude1, lng:length1};\nreturn coords; \n","outputs":1,"noerr":0,"x":510,"y":200,"wires":[["a24b08cf.22ebf8","dac1b7ce.4cc2c8"]]},{"id":"4a0b74fb.d10fcc","type":"http response","z":"76138ea1.88752","name":"","statusCode":"","headers":{},"x":484,"y":131,"wires":[]},{"id":"dac1b7ce.4cc2c8","type":"debug","z":"76138ea1.88752","name":"","active":true,"console":"false","complete":"false","x":990,"y":480,"wires":[]},{"id":"a24b08cf.22ebf8","type":"google geocoding","z":"76138ea1.88752","name":"find_address_from_coords","geocodeBy":"coordinates","address":"","lat":"msg.payload.lat","lon":"msg.payload.lng","googleAPI":"","bounds":"","language":"es","region":"","components":"","x":740,"y":200,"wires":[["dac1b7ce.4cc2c8"]]}]
You shouldn't be putting msg.payload.lat or msg.payload.lon in the config dialog. If you are passing those values in via a message object you need to leave them blank in the config dialog.
Next, as mentioned in the README.md and the info bar in Node-RED, you need to set the msg.location.lat and msg.location.lon on the incoming message to pass those value to the node.
So basically your function node should look a little bit more like this:
var coords ={};
latitude= parseFloat(msg.payload.lat).toFixed(7);
latitude1 = parseFloat(latitude);
var length = parseFloat(msg.payload.lng).toFixed(7);
var length1= parseFloat(length);
coords.location = {lat:latitude1, lon:length1};
return coords;

what is the meaning of this error Couldn't find string in telnet output ()

I am geeting this error message " error Couldn't find string in telnet output () " while running a test plan using TCL.What is the meaning of this error and why i am getting this type of error.
Well, it should mean exactly what it says.
You are expecting a certain string to be returned from the thing you're testing (such as 'login: '), and that string is not appearing (maybe you're getting 'Log In:' instead, for example).
You need to figure out what's actually coming out and adjust your expectations accordingly.

Resources