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

rename maps wrong new names #38

Closed
BrianDiggs opened this issue Apr 12, 2011 · 2 comments
Closed

rename maps wrong new names #38

BrianDiggs opened this issue Apr 12, 2011 · 2 comments

Comments

@BrianDiggs
Copy link

Summary

The newly promoted rename function in plry 1.5 does not map the new names correctly. A renaming of the requested columns to rename is made, but not to the correct new names

Reproducible code

This code example is drawn from coord-cartesian-flipped.r in ggplot2 which exposed the bug.

data <- structure(list(ymax = 0.819148936170213, ymin = 0.525145067698259, 
  x = 0.17741935483871, xmin = 0.0564516129032258, xmax = 0.298387096774194, 
  colour = "grey20", size = 0.5, linetype = 1, group = 1, alpha = 1, 
  fill = "#FFFFFFFF"), .Names = c("ymax", "ymin", "x", "xmin", 
  "xmax", "colour", "size", "linetype", "group", "alpha", "fill"
  ), row.names = c(NA, -1L), class = "data.frame")
plyr::rename(data, c(
  x = "y",       y = "x", 
  xend = "yend", yend = "xend", 
  xmin = "ymin", ymin = "xmin",
  xmax = "ymax", ymax = "xmax")
)

Actual results

          y         x      yend       xend      ymin colour size linetype group
1 0.8191489 0.5251451 0.1774194 0.05645161 0.2983871 grey20  0.5        1     1
  alpha      fill
1     1 #FFFFFFFF

Expected results

       xmax      xmin         y       ymin      ymax colour size linetype group
1 0.8191489 0.5251451 0.1774194 0.05645161 0.2983871 grey20  0.5        1     1
  alpha      fill
1     1 #FFFFFFFF

Note that this is the result given by reshape::rename with the same arguments.

Source of problem

The new names that are given are pulled from the new names in the order they are listed, not in the order that they match the old names.

To fix the problem, in plyr::reshape the line

setNames(x, ifelse(is.na(name_match), old_names, new_names))

should be

setNames(x, ifelse(is.na(name_match), old_names, new_names[name_match]))

Workarounds

None known.

Caveats

Inside the ggplot2 code, rename uses plyr::rename, while at the command prompt, rename uses reshape::rename. This is why the explicit package notation is needed in the function calls.

Session info

R version 2.13.0 RC (2011-04-10 r55401)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
[1] ggplot2_0.8.9 proto_0.3-9.1 reshape_0.8.4 plyr_1.5     

loaded via a namespace (and not attached):
[1] tools_2.13.0

@BrianDiggs
Copy link
Author

Too slow on my bug report; fixed in SHA: 4119984

@hadley
Copy link
Owner

hadley commented Apr 12, 2011

Thanks - I'll probably release plyr 1.5.1 in the next week or so.

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