GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Allow user to see when coercion happens · Issue #142 · Rcpp11/Rcpp11

Allow user to see when coercion happens #142

New issue
Copy link
New issue
Copy link
Open
Open
Allow user to see when coercion happens#142
Copy link
Labels
enhancement

Description

@kevinushey
kevinushey
opened on Apr 11, 2014
Issue body actions

E.g. defining RCPP_WARN_ON_COERCE would warn whenever r_cast is called. Maybe r_coerce as well?

Activity

  1. kevinushey
    added
    enhancement
    on Apr 11, 2014
  2. romainfrancois commented on Apr 11, 2014

    @romainfrancois
    romainfrancois
    on Apr 11, 2014
    Contributor
    More actions

    Perhaps in Vector(SEXP) it makes sense, although perhaps the default should be to error when e.g. someone wants to make a NumericVector out of a INTSXP which is the common source of coercion.

    We could have some explicit way of saying that coercion is fine.

  3. kevinushey commented on Apr 11, 2014

    @kevinushey
    kevinushey
    on Apr 11, 2014
    ContributorAuthor
    More actions

    Having coercion off by default makes sense to me as well. It makes more sense in R where the distinction between double and int shouldn't matter for most use cases; this is less true with C++.

  4. romainfrancois commented on Apr 12, 2014

    @romainfrancois
    romainfrancois
    on Apr 12, 2014
    Contributor
    More actions

    The bonus is that it also takes care of this problem:

    void alter( NumericVector x){
        x[0] = 1 ;
    }
    

    if you pass a numeric vector to alter its data is altered, that's fine our classes are proxies to the underlying SEXP. But if you pass an integer vector, then what is altered is the coerced data. This is usually hard to explain. So this free coercion has a price.

  5. kevinushey
    added a commit that references this issue on Apr 15, 2014

    Error on coerce by default when ctor-ing Vector from SEXP (#142)

    489bb4b
  6. kevinushey commented on Apr 15, 2014

    @kevinushey
    kevinushey
    on Apr 15, 2014
    ContributorAuthor
    More actions

    In the coerce branch, the ctor from SEXP now has a coerce argument, defaulting to false. It throws an error if one tries to construct a vector from a SEXP of different type.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.