Coder Social home page Coder Social logo

Comments (4)

vnijs avatar vnijs commented on July 2, 2024

@hadley Thanks for checking how changes to tidyr will affect others! Really appreciated.

The tab below used to gather fine but doesn't with the new tidyr. For 4/5 cases I switched to as.data.frame as that seems simpler and gives me what I need (and is not likely to change any time soon :)).

More interesting, perhaps, is the segfault I ran into (see second block below).

tab <- structure(c(39.1067931038135, 63.5264195668282, 32.4450680955929, 
52.704884372479), class = "table", .Dim = c(2L, 2L), .Dimnames = structure(list(
    c("Low Income", "High Income"), c("WS Journal", "USA Today"
    )), .Names = c("", "")))

tab %>% data.frame(., check.names = FALSE)

I had been using gather_ and as I was trying to figure out what was going on and trying to drop a variable I got segfault in R-gui on mac (3.2.2) running the code below:

tab <- structure(c(162.787931034483, 100.212068965517, 196.212068965517, 
120.787931034483), .Dim = c(2L, 2L), .Dimnames = structure(list(
    c("Low Income", "High Income"), c("WS Journal", "USA Today"
    )), .Names = c("", "")))

tab %>% 
  data.frame(., check.names = FALSE) %>%
  mutate(rnames = rownames(.)) %>% 
  gather_(., "variable", "values", -which(colnames(.) == "rnames"))

from radiant.

hadley avatar hadley commented on July 2, 2024

This works:

tab %>% 
  gather(variable, values, -rnames)

so I think something is wrong with your column spec, and tidyr isn't doing a good job of warning. Let me look more

from radiant.

hadley avatar hadley commented on July 2, 2024

Ok, now I get: Error: Unknown column names: -3.

You need:

tab %>% 
  data.frame(., check.names = FALSE) %>%
  mutate(rnames = rownames(.)) %>% 
  gather_(., "variable", "values", setdiff(colnames(.), "rnames")))

from radiant.

vnijs avatar vnijs commented on July 2, 2024

Hadn't thought about setdiff. Nice. Could a setdiff example perhaps be added to the documentation for gather_? Similarly, something like the below would be a nice add-on for the dplyr::select_ documentation. Thanks @hadley

select_(iris, .dots = setdiff(colnames(iris), c("Petal.Length", "Petal.Width")))

from radiant.

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.