Giter Site home page Giter Site logo

Comments (6)

strengejacke avatar strengejacke commented on June 9, 2024 1

ok, I think the docs are fine. regex modulates the select-string when we don't have select-helpers, and if we have select-helpers, we only have regular expressions

from datawizard.

etiennebacher avatar etiennebacher commented on June 9, 2024

The proper regex is \\. otherwise it selects everything:

library(datawizard)

iris |>
  data_select(contains("\\.")) |> 
  head()
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width
#> 1          5.1         3.5          1.4         0.2
#> 2          4.9         3.0          1.4         0.2
#> 3          4.7         3.2          1.3         0.2
#> 4          4.6         3.1          1.5         0.2
#> 5          5.0         3.6          1.4         0.2
#> 6          5.4         3.9          1.7         0.4

I can update the readme

from datawizard.

strengejacke avatar strengejacke commented on June 9, 2024

But regex is set to FALSE.

I think the problematic code is here:

.select_helper <- function(expr, data, ignore_case, regex, verbose) {
  lst_expr <- as.list(expr)

  # need this if condition to distinguish between starts_with("Sep") (that we
  # can use directly) and starts_with(i) (where we need to get i)
  if (length(lst_expr) == 2L && typeof(lst_expr[[2]]) == "symbol") {
    collapsed_patterns <- .dynGet(lst_expr[[2]], inherits = FALSE, minframe = 0L)
  } else {
    collapsed_patterns <- paste(unlist(lst_expr[2:length(lst_expr)]), collapse = "|")
  }

  helper <- insight::safe_deparse(lst_expr[[1]])

  rgx <- switch(helper,
    "starts_with" = paste0("^(", collapsed_patterns, ")"),
    "ends_with" = paste0("(", collapsed_patterns, ")$"),
    "contains" = paste0("(", collapsed_patterns, ")"),
    "regex" = collapsed_patterns,
    insight::format_error("There is no select helper called '", helper, "'.")
  )
  grep(rgx, colnames(data), ignore.case = ignore_case)
}

Argument regex is passed, but not evaluated.

from datawizard.

strengejacke avatar strengejacke commented on June 9, 2024

If we want a different behaviour, we should somewhere mention this in the code. The code from the readme used to work, i.e. contains(".") selected everything with dots when regex was FALSE.

from datawizard.

etiennebacher avatar etiennebacher commented on June 9, 2024

But I thought regex only applies when select is a character (and that's what the docs say) so whether regex is TRUE or FALSE shouldn't matter in the example above

from datawizard.

strengejacke avatar strengejacke commented on June 9, 2024

But I thought regex only applied when select was a character (and that's what the docs say) so whether regex is TRUE or FALSE shouldn't matter in the example above

Yes. It was maybe an old artifact from the readme examples.

from datawizard.

Related Issues (20)

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.