Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empasize.cols and emphasize.rows alters the data for empty cells #176

Closed
romantseg opened this issue Jun 2, 2015 · 1 comment
Closed

Comments

@romantseg
Copy link
Contributor

While I was working on more tests, I saw an odd behavior that seems to be a bug

> df <- data.frame(a=c("", 1, 1), b=1:3, c=c("", "", 2))
> pander(df)

-----------
 a   b   c 
--- --- ---
     1     

 1   2     

 1   3   2 
-----------

> pander(df, emprashize.cols = 1, emphasize.rows = c(1,2))

-----------
 a   b   c 
--- --- ---
        *2*

*1* *1*    

 1   3   2 
-----------

I added it to not forget to have a look at it later

@romantseg
Copy link
Contributor Author

After a bit more investigation it turns out that the problem is this line.

Problem is that apply for rows returns a transposed data.frame which can't be assigned back. For example,

> df <- data.frame(a=1:3, b=1:3, c=1:3)
> apply(df[c(1,2),,drop=F], c(1), identity)
  1 2
a 1 2
b 1 2
c 1 2
> df[c(1,2),] <- apply(df[c(1,2),,drop=F], c(1), identity)
> df
  a b c
1 1 1 2
2 1 2 2
3 3 3 3

Looking at documentation for apply, it seems to be consistent

If each call to FUN returns a vector of length n, then apply returns an array of dimension c(n, dim(X)[MARGIN]) if n > 1.

So it seems that when apply is only used for rows it should be transposed before assigning back

@daroczig , what do you think?

romantseg added a commit that referenced this issue Jun 8, 2015
@daroczig daroczig closed this as completed Jun 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants