[Rcpp-devel] Testing for existence of named components
Romain Francois
romain at r-enthusiasts.com
Thu Mar 29 20:59:03 CEST 2012
Le 29/03/12 20:18, Dirk Eddelbuettel a écrit :
>
> On 29 March 2012 at 18:51, Patrick Burns wrote:
> | On 29/03/2012 18:33, Dirk Eddelbuettel wrote:
> |>
> |> On 29 March 2012 at 19:12, Romain Francois wrote:
> |> | Le 28/03/12 13:56, Ulrich Bodenhofer a écrit :
> |> |> Hi,
> |> |>
> |> |> My question is the following: is there any way of checking in whether a
> |> |> component of an Rcpp list (or vector) with a given name exists in this
> |> |> list. If I simply try accessing a non-existing component, I get an
> |> |> "index out of bounds" error. Trying to catch a possible exception did
> |> |> not work either. I also browsed the Rcpp package source code, but
> |> |> unfortunately I got lost. Sorry if this has been addressed on this list
> |> |> before. At least I googled in many different ways, but could not find
> |> |> anything. Any ideas? Any help is gratefully appreciated!
> |> |>
> |> |> Thanks and best regards,
> |> |> Ulrich
> |> |
> |> | Hello,
> |> |
> |> | I commited the has_element_called method on the Vector template (vectors
> |> | of all sorts, incl lists).
> |>
> |> +1, but how about just calling it 'contains' rather 'has_element_called' ?
> |
> | I think 'contains' would imply a value
> | in the vector rather than a name. The
> | extra typing might be worth avoiding
> | that confusion.
>
> While that is true, it cannot deflect away from the fact that Hadley and I
> are in a deadly mano-a-mano battle about the extended use, or, in my case,
> strict avoidance, of underscores. That is /extremely serious/ business.
>
> So how about hasElementCalled() then?
>
> Or given that these are 'names' how about
>
> hasElementNamed()
>
> pr maybe
>
> containsName()
Sure. Whatever makes anyone happy ;-)
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
R Graph Gallery: http://addictedtor.free.fr/graphiques
blog: http://romainfrancois.blog.free.fr
|- http://bit.ly/xbKv0R : Crawling facebook with R
|- http://bit.ly/v3WB8S : ... And now for solution 17, still using Rcpp
`- http://bit.ly/uaQDGr : int64: 64 bit integer vectors for R
More information about the Rcpp-devel
mailing list