Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

216 lines
5.3KB

  1. #' Animates a full join
  2. #'
  3. #' @param x the x dataset
  4. #' @param y the y dataset
  5. #' @param by the by arguments for the join
  6. #' @param export the export type, either gif, first or last. The latter two
  7. #' export ggplots of the first/last state of the join
  8. #' @param ... further arguments passed to base_plot
  9. #'
  10. #' @return either a gif or a ggplot
  11. #' @export
  12. #'
  13. #' @examples
  14. #' x <- data_frame(
  15. #' id = 1:3,
  16. #' x = paste0("x", 1:3)
  17. #' )
  18. #' y <- data_frame(
  19. #' id = (1:4)[-3],
  20. #' y = paste0("y", (1:4)[-3])
  21. #' )
  22. #'
  23. #' animate_full_join(x, y, by = "id", export = "first")
  24. #' animate_full_join(x, y, by = "id", export = "last")
  25. #'
  26. #' \dontrun{
  27. #' # to save the ggplot, use
  28. #' fj <- animate_full_join(x, y, by = "id", export = "last")
  29. #' ggsave("full-join.pdf", fj)
  30. #'
  31. #' animate_full_join(x, y, by = "id", export = "gif")
  32. #' # to save the gif, use
  33. #' fj <- animate_full_join(x, y, by = "id", export = "gif")
  34. #' anim_save(fj, "full-join.gif")
  35. #' }
  36. #'
  37. animate_full_join <- function(x, y, by, export = "gif", ...) {
  38. animate_join(x, y, by, type = "full_join", export = export, ...)
  39. }
  40. #' Animates an inner join
  41. #'
  42. #' @inheritParams animate_full_join
  43. #'
  44. #' @return either a gif or a ggplot
  45. #' @export
  46. #'
  47. #' @examples
  48. #' x <- data_frame(
  49. #' id = 1:3,
  50. #' x = paste0("x", 1:3)
  51. #' )
  52. #' y <- data_frame(
  53. #' id = (1:4)[-3],
  54. #' y = paste0("y", (1:4)[-3])
  55. #' )
  56. #'
  57. #' animate_inner_join(x, y, by = "id", export = "first")
  58. #' animate_inner_join(x, y, by = "id", export = "last")
  59. #'
  60. #' \dontrun{
  61. #' # to save the ggplot, use
  62. #' ij <- animate_inner_join(x, y, by = "id", export = "last")
  63. #' ggsave("inner-join.pdf", ij)
  64. #'
  65. #' animate_inner_join(x, y, by = "id", export = "gif")
  66. #' # to save the gif, use
  67. #' ij <- animate_inner_join(x, y, by = "id", export = "gif")
  68. #' anim_save(ij, "inner-join.gif")
  69. #' }
  70. #'
  71. animate_inner_join <- function(x, y, by, export = "gif", ...) {
  72. animate_join(x, y, by, type = "inner_join", export = export, ...)
  73. }
  74. #' Animates a left join
  75. #'
  76. #' @inheritParams animate_full_join
  77. #'
  78. #' @return either a gif or a ggplot
  79. #' @export
  80. #'
  81. #' @examples
  82. #' x <- data_frame(
  83. #' id = 1:3,
  84. #' x = paste0("x", 1:3)
  85. #' )
  86. #' y <- data_frame(
  87. #' id = (1:4)[-3],
  88. #' y = paste0("y", (1:4)[-3])
  89. #' )
  90. #'
  91. #' animate_left_join(x, y, by = "id", export = "first")
  92. #' animate_left_join(x, y, by = "id", export = "last")
  93. #'
  94. #' \dontrun{
  95. #' # to save the ggplot, use
  96. #' lj <- animate_left_join(x, y, by = "id", export = "last")
  97. #' ggsave("left-join.pdf", lj)
  98. #'
  99. #' animate_left_join(x, y, by = "id", export = "gif")
  100. #' # to save the gif, use
  101. #' lj <- animate_left_join(x, y, by = "id", export = "gif")
  102. #' anim_save(lj, "left-join.gif")
  103. #' }
  104. #'
  105. animate_left_join <- function(x, y, by, export = "gif", ...) {
  106. animate_join(x, y, by, type = "left_join", export = export, ...)
  107. }
  108. #' Animates a right join
  109. #'
  110. #' @inheritParams animate_full_join
  111. #'
  112. #' @return either a gif or a ggplot
  113. #' @export
  114. #'
  115. #' @examples
  116. #' x <- data_frame(
  117. #' id = 1:3,
  118. #' x = paste0("x", 1:3)
  119. #' )
  120. #' y <- data_frame(
  121. #' id = (1:4)[-3],
  122. #' y = paste0("y", (1:4)[-3])
  123. #' )
  124. #'
  125. #' animate_right_join(x, y, by = "id", export = "first")
  126. #' animate_right_join(x, y, by = "id", export = "last")
  127. #'
  128. #' \dontrun{
  129. #' # to save the ggplot, use
  130. #' rj <- animate_right_join(x, y, by = "id", export = "last")
  131. #' ggsave("right-join.pdf", rj)
  132. #'
  133. #' animate_right_join(x, y, by = "id", export = "gif")
  134. #' # to save the gif, use
  135. #' rj <- animate_right_join(x, y, by = "id", export = "gif")
  136. #' anim_save(rj, "right-join.gif")
  137. #' }
  138. #'
  139. animate_right_join <- function(x, y, by, export = "gif", ...) {
  140. animate_join(x, y, by, type = "right_join", export = export, ...)
  141. }
  142. #' Animates a semi join
  143. #'
  144. #' @inheritParams animate_full_join
  145. #'
  146. #' @return either a gif or a ggplot
  147. #' @export
  148. #'
  149. #' @examples
  150. #' x <- data_frame(
  151. #' id = 1:3,
  152. #' x = paste0("x", 1:3)
  153. #' )
  154. #' y <- data_frame(
  155. #' id = (1:4)[-3],
  156. #' y = paste0("y", (1:4)[-3])
  157. #' )
  158. #'
  159. #' animate_semi_join(x, y, by = "id", export = "first")
  160. #' animate_semi_join(x, y, by = "id", export = "last")
  161. #'
  162. #' \dontrun{
  163. #' # to save the ggplot, use
  164. #' sj <- animate_semi_join(x, y, by = "id", export = "last")
  165. #' ggsave("semi-join.pdf", sj)
  166. #'
  167. #' animate_semi_join(x, y, by = "id", export = "gif")
  168. #' # to save the gif, use
  169. #' sj <- animate_semi_join(x, y, by = "id", export = "gif")
  170. #' anim_save(sj, "semi-join.gif")
  171. #' }
  172. #'
  173. animate_semi_join <- function(x, y, by, export = "gif", ...) {
  174. animate_join(x, y, by, type = "semi_join", export = export, ...)
  175. }
  176. #' Animates an anti join
  177. #'
  178. #' @inheritParams animate_full_join
  179. #'
  180. #' @return either a gif or a ggplot
  181. #' @export
  182. #'
  183. #' @examples
  184. #' x <- data_frame(
  185. #' id = 1:3,
  186. #' x = paste0("x", 1:3)
  187. #' )
  188. #' y <- data_frame(
  189. #' id = (1:4)[-3],
  190. #' y = paste0("y", (1:4)[-3])
  191. #' )
  192. #'
  193. #' animate_anti_join(x, y, by = "id", export = "first")
  194. #' animate_anti_join(x, y, by = "id", export = "last")
  195. #'
  196. #' \dontrun{
  197. #' # to save the ggplot, use
  198. #' aj <- animate_anti_join(x, y, by = "id", export = "last")
  199. #' ggsave("anti-join.pdf", aj)
  200. #'
  201. #' animate_anti_join(x, y, by = "id", export = "gif")
  202. #' # to save the gif, use
  203. #' aj <- animate_anti_join(x, y, by = "id", export = "gif")
  204. #' anim_save(aj, "anti-join.gif")
  205. #' }
  206. #'
  207. animate_anti_join <- function(x, y, by, export = "gif", ...) {
  208. animate_join(x, y, by, type = "anti_join", export = export, ...)
  209. }