Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

94 lines
2.5KB

  1. #' Animates a join operations
  2. #'
  3. #' Functions to visualise the join operations either static as a ggplot, or
  4. #' dynamic as a gif.
  5. #'
  6. #' @param x the x dataset
  7. #' @param y the y dataset
  8. #' @param by the by arguments for the join
  9. #' @param export the export type, either gif, first or last. The latter two
  10. #' export ggplots of the first/last state of the join
  11. #' @param ... further arguments passed to base_plot
  12. #'
  13. #' @return either a gif or a ggplot
  14. #'
  15. #' @seealso \code{\link[dplyr]{join}}
  16. #'
  17. #' @name animate_join
  18. #' @examples
  19. #' x <- data_frame(
  20. #' id = 1:3,
  21. #' x = paste0("x", 1:3)
  22. #' )
  23. #' y <- data_frame(
  24. #' id = (1:4)[-3],
  25. #' y = paste0("y", (1:4)[-3])
  26. #' )
  27. #'
  28. #' # Animate the first or last state of the join
  29. #' animate_full_join(x, y, by = "id", export = "first")
  30. #' animate_full_join(x, y, by = "id", export = "last")
  31. #'
  32. #' # animate the transition as a gif (default)
  33. #' \donttest{
  34. #' animate_full_join(x, y, by = "id", export = "gif")
  35. #' }
  36. #'
  37. #' # different options include
  38. #' \donttest{
  39. #' animate_full_join(x, y, by = "id")
  40. #' animate_inner_join(x, y, by = "id")
  41. #' animate_left_join(x, y, by = "id")
  42. #' animate_right_join(x, y, by = "id")
  43. #' animate_semi_join(x, y, by = "id")
  44. #' animate_anti_join(x, y, by = "id")#'
  45. #' }
  46. #'
  47. #' # Save the results
  48. #' \donttest{
  49. #' # to save the ggplot, use
  50. #' fj <- animate_full_join(x, y, by = "id", export = "last")
  51. #' ggsave("full-join.pdf", fj)
  52. #'
  53. #' # to save the gif, use
  54. #' fj <- animate_full_join(x, y, by = "id", export = "gif")
  55. #' anim_save(fj, "full-join.gif")
  56. #' }
  57. NULL
  58. #' @rdname animate_join
  59. #' @export
  60. animate_full_join <- function(x, y, by, export = "gif", ...) {
  61. animate_join(x, y, by, type = "full_join", export = export, ...)
  62. }
  63. #' @rdname animate_join
  64. #' @export
  65. animate_inner_join <- function(x, y, by, export = "gif", ...) {
  66. animate_join(x, y, by, type = "inner_join", export = export, ...)
  67. }
  68. #' @rdname animate_join
  69. #' @export
  70. animate_left_join <- function(x, y, by, export = "gif", ...) {
  71. animate_join(x, y, by, type = "left_join", export = export, ...)
  72. }
  73. #' @rdname animate_join
  74. #' @export
  75. animate_right_join <- function(x, y, by, export = "gif", ...) {
  76. animate_join(x, y, by, type = "right_join", export = export, ...)
  77. }
  78. #' @rdname animate_join
  79. #' @export
  80. animate_semi_join <- function(x, y, by, export = "gif", ...) {
  81. animate_join(x, y, by, type = "semi_join", export = export, ...)
  82. }
  83. #' @rdname animate_join
  84. #' @export
  85. animate_anti_join <- function(x, y, by, export = "gif", ...) {
  86. animate_join(x, y, by, type = "anti_join", export = export, ...)
  87. }