[R-sig-Geo] integer parameter treatment in doGRASS - WAS: spGRASS6 issue
Rainer M Krug
r.m.krug at gmail.com
Thu Feb 7 12:12:27 CET 2013
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 07/02/13 11:48, Roger Bivand wrote:
> On Thu, 7 Feb 2013, Rainer M Krug wrote:
>
> On 06/02/13 13:22, Rainer M Krug wrote:
>>>> On 06/02/13 12:55, Roger Bivand wrote:
>>>>> On Wed, 6 Feb 2013, R.S. Bhalla wrote:
>>>>
>>>>>> Dear List, I have run into trouble with the execGRASS command copied below and can't
>>>>>> figure out what I'm doing wrong. It runs fine without the size=11 argument (takes
>>>>>> the default value of 3). Can
>>>>
>>>>>> storage.mode(11)
>>>>> [1] "double"
>>>>>> is.integer(11)
>>>>> [1] FALSE
>>>>>> is.integer(11L)
>>>>> [1] TRUE
>>>>
>>>>> Just because it looks like an integer, it doesn't mean it is.
>>>>
>>>> Hi Roger
>>>>
>>>> this has bittan many users, including myself, as it is a little aux contraire to R, as
>>>> here 11 is acepted as integer in most circumstances.
>>>>
>>>> Would it be possible to use a different check for integer e.g.
>>>>
>>>> if(as.integer(x) == x) then {x <- as.integer(x)} else {ERROR}
>>>>
>>>> I have the feeling that would be more in line with the treating in R of different
>>>> numerical storage modes.
>
> Hi Roger,
>
> To follow up:
>
> in the function doGRASS, I would suggest to change:
>
>
>
> else if (pmv[i] == "integer") { if (!is.integer(parameters[[i]])) stop(paste("Parameter <",
> names(parameters)[i], "> does not have integer value", sep = "")) }
>
>
> to
>
> else if (pmv[i] == "integer") { if (!(as.integer(parameters[[i]]==parameters[[i]])) {
> stop(paste("Parameter <", names(parameters)[i], "> does not have integer value", sep = "")) }
> else { parameters[[i]] <- as.integer(parameters[[i]] } }
>
> which will cause the error message when a not integer *value* has been submitted, irrespective
> of the storage mode. If it is an integer value, the parameter[[i]] wil be stored as an
> integer.
>
> A side effect would be that even "11" would be accepted, which is actually quite nice.
>
>
>> I've commited some changes to the spgrass6 module of the rspatial project on R-forge
>> (revision 1349), but not the conversion of strings to integer or numeric, which I think must
>> be the users' responsibility, as failure is not an error but an NA. Please let me know if
>> this helps. Maybe the statgrass list is a better forum?
>
>> Roger
Hi Roger
looks fine with me. Conversion from character to numeric is not necessary: agreed.
I cc this to statsgrass for the record and possibly further comments
Thanks,
Rainer
>
>
>
> In addition, One could even add the same construct to the float test:
>
> else if (pmv[i] == "float") { if (!(as.numeric(parameters[[i]]==parameters[[i]])) {
> stop(paste("Parameter <", names(parameters)[i], "> does not have numeric value", sep = "")) }
> else { parameters[[i]] <- as.numeric(parameters[[i]] } }
>
>
> I also would suggest to change the error message for float from "not have a float value" to
> "does not have a numeric value" as this is more consistent, as this would be more consistent
> with R terminology.
>
> Cheers,
>
> Rainer
>
>
>>>>
>>>> Cheers,
>>>>
>>>> Rainer
>>>>
>>>>
>>>>
>>>>
>>>>> Roger
>>>>
>>>>>> someone please help. Thanks in advance, Ravi
>>>>>>
>>>>>> Command: execGRASS("r.neighbors", parameters=list(input=patmap, output=n11map,
>>>>>> method="median", size=11), flags=c("overwrite", "c"))
>>>>>>
>>>>>> Error: Error in doGRASS(cmd, flags = flags, ..., parameters = parameters, echoCmd =
>>>>>> echoCmd) : Parameter <size> does not have integer value
>>>>>>
>>>>>>
>>>>
>>>>
>>>>
>
>>
>
- --
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys.
(Germany)
Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa
Tel : +33 - (0)9 53 10 27 44
Cell: +33 - (0)6 85 62 59 98
Fax : +33 - (0)9 58 10 27 44
Fax (D): +49 - (0)3 21 21 25 22 44
email: Rainer at krugs.de
Skype: RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBAgAGBQJRE4wbAAoJENvXNx4PUvmCMAQIAKGMTPl8DW9nb3qEtCbZQ5+m
INGt1OKoU9hL5+uXJ0zMndU4uqqg0iG1pKe84O39rsUGrPoL8aAybarmHs0H0PGn
sotxnsUpJbc0SxAp4d6c8+kZf3AkV68yh0TKZDkNKUhxSjXskmBNDxQzXoRRryha
S8d4fifPYtkWTYoNjl4p3AlosurFdg+xVyPLZNTV9/V1P+8mPl6KPLc7RHM4fxfk
xFjYNuz3H5iL4I/dO7K/7FBRYOJDINKuIOrzCYf4ZMO6VO2K6fCEGGa2Ks3G+YsA
3Id8+jKy9Ac+ryGIOTf/HRYR/zfWU0H4LlcBnw2at0HuL+MNrDW7PJwDufhW0hY=
=r8+p
-----END PGP SIGNATURE-----
More information about the R-sig-Geo
mailing list