Code Monkey home page Code Monkey logo

Comments (5)

crvernon avatar crvernon commented on September 23, 2024 1

What I am saying is that whether the first occurrence or the last occurrence takes effect does not come from regular expression's feature. It comes from how the code is executed.

I agree. I didn't want users to be misled by assumptions that there would be some error raised if there were errors within their regular expressions, in terms of duplicated values in the query string. Since these query strings will likely be constructed manually, I believe they are prone to these types user error.

If you believe that the current representation of how this functions is sufficiently represented in your documentation, I will close the issue.

from datasailr.

niceume avatar niceume commented on September 23, 2024

Thank you for your comment!

Even when ^Hornet appears in regular expressions for both usa and japan, they both work. (i.e. they do not mask each other.)

The following code shows that ^Hornet in usa and ^Hornet in japan work.

library(datasailr)
data(mtcars)

sail(mtcars, '
germany = re/(^Merc|^Porsche|^Volvo)/
usa = re/(^Hornet|^Cadillac|^Lincoln|^Chrysler|^Dodge|^AMC|^Camaro|^Chevrolet|^Pontiac|^Ford)/
japan = re/(^Mazda|^Datsun|^Honda|^Toyota|^Hornet)/

_rowname_ =~ germany
type_germany = rexp_matched(1)
_rowname_ =~ usa
type_usa = rexp_matched(1)
_rowname_ =~ japan
type_japan = rexp_matched(1)
')

from datasailr.

crvernon avatar crvernon commented on September 23, 2024

Even when ^Hornet appears in regular expressions for both usa and japan, they both work. (i.e. they do not mask each other.)
The following code shows that ^Hornet in usa and ^Hornet in japan work.

I agree that this situation works; however, when the assignment occurs for a common field (e.g., type) only the first occurrence of the value (Hornet) will be recognized.

from datasailr.

niceume avatar niceume commented on September 23, 2024

when the assignment occurs for a common field (e.g., type) only the first occurrence of the value (Hornet) will be recognized.

This is true when regular expression matching is conducted in if-else's conditions. (you already seem to have mentioned)

In the following code, the last regular expression matching result overwrites the previous results, because those matching results are assigned to the same field (type).

library(datasailr)
data(mtcars)

sail(mtcars, '
germany = re/(^Merc|^Porsche|^Volvo)/
usa = re/(^Hornet|^Cadillac|^Lincoln|^Chrysler|^Dodge|^AMC|^Camaro|^Chevrolet|^Pontiac|^Ford)/
japan = re/(^Mazda|^Datsun|^Honda|^Toyota|^Hornet)/

_rowname_ =~ germany
type = rexp_matched(1)
_rowname_ =~ usa
type = rexp_matched(1)
_rowname_ =~ japan
type = rexp_matched(1)
')

I am sorry if I misunderstand what you are saying.

What I am saying is that whether the first occurrence or the last occurrence takes effect does not come from regular expression's feature. It comes from how the code is executed.

from datasailr.

niceume avatar niceume commented on September 23, 2024

I understand. When I make tutorials, I will keep it in mind. Thank you very much for your comments!

from datasailr.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.