renkun-ken / pipeR

Multi-Paradigm Pipeline Implementation
Other
169 stars 39 forks source link

Pipe's error #58

Closed dichika closed 10 years ago

dichika commented 10 years ago

Hi, I got an error below. How do I deal with such a case?

library(dplyr) library(pipeR) smp = Pipe(iris)$group_by(Species)$tally() colnames(smp) = c("V1","V2")

Error : attempt to set colnames on object with less than two dimensions

Thanks.

renkun-ken commented 10 years ago

It's a bit tricky to use Pipe() because it is very easy to obfuscate the Pipe object and the value (or data) in it.

If you want to access the value in the Pipe, you are actually ending the Pipe so you need to extract the value out from it.

smp = Pipe(iris)$group_by(Species)$tally()$value

If you still want to continue piping using Pipe, there are some walk-arounds:

> Pipe(iris)$group_by(Species)$tally()$setNames(c("V1","V2"))
<Pipe: tbl_df tbl data.frame>
Source: local data frame [3 x 2]

          V1 V2
1     setosa 50
2 versicolor 50
3  virginica 50

Your code colnames(smp) = c("V1","V2") is trying to set the colnames of the Pipe object rather than the data.frame in it. smp is a Pipe and does not know colnames so you can't directly set by colnames<-.

dichika commented 10 years ago

Thanks!!