09.qmd (9799B)
1 --- 2 title: Cohort 9 3 --- 4 5 {{< video https://www.youtube.com/embed/krPNeIt9qU4 >}} 6 7 <details> 8 9 <summary>Meeting chat log</summary> 10 ``` 11 00:11:08 Steffi LaZerte (she/her): I'll have to leave about 15-20min early today, sorry in advance! 12 00:11:40 Olivier Leroy: start 13 00:16:14 Steffi LaZerte (she/her): https://www.rstudio.com/wp-content/uploads/2016/02/advancedR.pdf 14 00:16:27 Howard Baek: Reacted to "https://www.rstudio...." with π 15 00:16:30 Jeffrey Stevens: Reacted to "https://www.rstudio...." with π 16 00:16:32 Olivier Leroy: https://www.rstudio.com/wp-content/uploads/2016/02/advancedR.pdf 17 00:16:34 Olivier Leroy: Reacted to "https://www.rstudio...." with π 18 00:16:41 Olivier Leroy: Ahah you were faster :p 19 00:16:55 Steffi LaZerte (she/her): Reacted to "Ahah you were faster..." with π 20 00:18:47 Gabby Palomo Munoz: I think you mean the arguments. 21 00:19:12 Olivier Leroy: Btw R return the last statement in a body function (always bit me) unless you have return() 22 00:19:50 Jo Hardin: what happens if you have two `return()` statements? 23 00:20:31 Steffi LaZerte (she/her): I think the first one it hits is the one it uses, so if you have an if / else you can have multiple returns 24 00:20:35 Olivier Leroy: The first one, I think has it exit the function to the parent environment 25 00:20:43 Jo Hardin: iβve also always called them βargumentsβ but the chapter makes a big deal about calling them βformalsβ. 26 00:21:18 Olivier Leroy: formal() ? 27 00:21:19 Jo Hardin: does anyone know why βformalsβ instead of βargumentsβ? and how they might be different? 28 00:21:20 Steffi LaZerte (she/her): I use options > arguments > (and now) formals, in order of increasing complexity or nit-pickyness :D 29 00:21:38 Gabby Palomo Munoz: formals? interesting? I thought it was arguments 30 00:22:07 Olivier Leroy: > sum 31 function (..., na.rm = FALSE) .Primitive("sum") 32 00:23:47 Steffi LaZerte (she/her): Replying to "does anyone know why..." 33 34 In the ?formals, they call them "formal arguments" 35 00:24:47 Olivier Leroy: Mean seems to dispatch 36 00:27:29 Olivier Leroy: I have this one on env function that always blew my mind: 37 38 ctr <- 0 39 f <- function(){ 40 ctr <<- ctr + 1 41 cat("this count currently has value", ctr, "\n") 42 } 43 } 44 45 c1 <- counter() 46 c2 <- counter() 47 48 49 c1() 50 c1() 51 c2() 52 ctr 53 00:28:40 Steffi LaZerte (she/her): Replying to "I have this one on e..." 54 55 I hate this π 56 00:28:45 Steffi LaZerte (she/her): So scary! 57 00:30:26 Olivier Leroy: Reacted to "So scary!" with π» 58 00:31:49 Howard Baek: Inside purrr functions 59 00:31:52 Gabby Palomo Munoz: Reacted to "Inside purrr functio..." with π― 60 00:31:59 Diana Garcia Cortes: Reacted to "Inside purrr functio..." with π― 61 00:31:59 Gabby Palomo Munoz: Replying to "Inside purrr functio..." 62 63 I was just gonna say this :D 64 00:32:27 Howard Baek: Replying to "Inside purrr functio..." 65 66 Thatβs the only place I use em π 67 00:32:44 Gabby Palomo Munoz: Replying to "Inside purrr functio..." 68 69 Yes apply and purrr ... trying to think where else... 70 00:34:53 Steffi LaZerte (she/her): Replying to "Inside purrr functio..." 71 72 Me too, I was thinking today how much I've been using multiline anonymous functions to map over a set of database connections in one of my projects 73 00:35:36 Derek Sollberger (he/him): "funs" here seems like when many R programmers would make a code package instead 74 00:38:20 Gabby Palomo Munoz: If we are going to see this later in another chapter maybe we can just move on with the rest. I'm sorry, not trying to be mean but we only have an hour. 75 00:38:35 Gabby Palomo Munoz: Ha 'mean' no pun intended. 76 00:38:46 Olivier Leroy: r$> mean[1] 77 Error in mean[1] : object of type 'closure' is not subsettable 78 00:38:55 Steffi LaZerte (she/her): That's where I know the term! Yes! "Closure is not subsettable" 79 00:39:23 Steffi LaZerte (she/her): Reacted to "Ha 'mean' no pun int..." with π 80 00:40:31 Derek Sollberger (he/him): Replying to "That's where I know ..." 81 82 Jenny Bryan's famous rstudio::conf() 2020 talk "Object of type 'closure' is not subsettable" (about debugging) 83 84 https://www.youtube.com/watch?v=vgYS-F8opgE 85 00:40:41 Gabby Palomo Munoz: Reacted to "Jenny Bryan's famous..." with π― 86 00:41:09 Steffi LaZerte (she/her): Reacted to "Jenny Bryan's famous..." with π― 87 00:41:12 Olivier Leroy: Reacted to "Jenny Bryan's famous..." with π― 88 00:41:16 Gabby Palomo Munoz: Replying to "That's where I know ..." 89 90 I swear there's always a Jenny Bryan's talk somewhere to clarify any complex topic 91 00:41:33 Jo Hardin: Reacted to "I swear there's alwa..." with π― 92 00:43:29 Olivier Leroy: do.call(rbind, lapply(bucket[["Contents"]]), function(x) x[["Key"]]) 93 94 Is a way to list all key in a s3 bucket as an example of args/anonymous function 95 00:44:29 Gabby Palomo Munoz: Quick question about do.call() Let's say I have a function I created that has three arguments. my_fun <- function(x, y, z){ body} and then I use it in do.call(). I just list the arguments as this: do.call(list, list$x, list$y, list$z) 96 00:44:42 Olivier Leroy: Reacted to "Quick question about..." with π 97 00:44:45 Gabby Palomo Munoz: I am always confused by this which is why I go to lapply LOL but I like do.call() 98 00:45:15 Olivier Leroy: Do.call(function, list(named args)) 99 00:45:35 Derek Sollberger (he/him): Replying to "I am always confused..." 100 101 Agree. I think do.call() is useful to mention en route to learning about *apply() 102 00:45:41 Gabby Palomo Munoz: Replying to "Quick question about..." 103 104 Yes the function goes first lol, and then I list the arguments. Oh perfect. thanks Olivier!!! 105 00:45:50 Olivier Leroy: Reacted to "Yes the function goe..." with π 106 00:45:50 Gabby Palomo Munoz: Reacted to "Agree. I think do.c..." with β€οΈ 107 00:46:51 Olivier Leroy: This one overwriting the same name is so dangerous π 108 00:47:23 Gabby Palomo Munoz: Replying to "This one overwriting..." 109 110 temp 111 00:47:38 Gabby Palomo Munoz: Reacted to "This one overwriting..." with π― 112 00:48:36 Derek Sollberger (he/him): caution: the magrittr pipe might still be needed for ".", for example: 113 114 df %>% lm(y ~ x, data = .) 115 00:48:54 Steffi LaZerte (she/her): Replying to "caution: the magritt..." 116 117 You can use 118 00:48:55 Gabby Palomo Munoz: Replying to "caution: the magritt..." 119 120 but not with the native pipe? 121 00:49:01 Steffi LaZerte (she/her): Replying to "caution: the magritt..." 122 123 df |> lm(y ~ x, data = _) 124 00:49:07 Derek Sollberger (he/him): Reacted to "df |> lm(y ~ x, data..." with π» 125 00:49:14 Gabby Palomo Munoz: Replying to "caution: the magritt..." 126 127 Actually, I am not clear on when to use the . so I use it whenever I see an error 128 00:49:26 Steffi LaZerte (she/her): Replying to "caution: the magritt..." 129 130 But it's not as flexible and must be a named argument and can't be inside another nested function (drives me nuts!) 131 00:49:35 Gabby Palomo Munoz: Reacted to "df |> lm(y ~ x, data..." with π€― 132 00:49:35 Howard Baek: Do you guys load magrittr when you are using its other operators like %T>%? 133 00:50:28 Gabby Palomo Munoz: Replying to "Do you guys load mag..." 134 135 I use |> but I have it set like this in RStudio settings. If you have the magrittr pipe as default then you don't have to load the package. At least that's my understanding. 136 00:50:38 Steffi LaZerte (she/her): Replying to "Do you guys load mag..." 137 138 Sometimes, but I use that operator so rarely, it's usually easier (and easier to read) to just break out of the pipe for it 139 00:50:48 Howard Baek: Replying to "Do you guys load mag..." 140 141 Yeah I agree 142 00:51:18 Steffi LaZerte (she/her): Replying to "Do you guys load mag..." 143 144 Now I'm trying to use the base pipe as my default (it also looks better in my font :D ) 145 00:51:26 Derek Sollberger (he/him): Reacted to "I use |> but I have ..." with π§ 146 00:52:01 Howard Baek: Replying to "Do you guys load mag..." 147 148 Are you using the Hadley font? 149 00:52:20 Olivier Leroy: Reacted to "df |> lm(y ~ x, data..." with π€― 150 00:52:25 Steffi LaZerte (she/her): Replying to "Do you guys load mag..." 151 152 Fira Code 153 00:52:33 Steffi LaZerte (she/her): Replying to "Do you guys load mag..." 154 155 I had no idea there was a Hadley font! 156 00:52:34 Howard Baek: Replying to "Do you guys load mag..." 157 158 Yeah same haha 159 00:52:42 Gabby Palomo Munoz: Replying to "Do you guys load mag..." 160 161 the native pipe is so much cleaner looking I agree 162 00:52:45 Steffi LaZerte (she/her): I have to run everyone, sorry! It's been a great conversation, see you next week! 163 00:52:51 Olivier Leroy: Reacted to "I have to run everyo..." with π 164 00:52:51 Howard Baek: Replying to "Do you guys load mag..." 165 166 Oh I meant the font that Hadley Wickham uses, which is FiraCode 167 00:52:52 Gabby Palomo Munoz: Reacted to "I have to run everyo..." with ππ» 168 00:52:55 Howard Baek: Reacted to "I have to run everyo..." with π 169 00:52:58 Howard Baek: Reacted to "I have to run everyo..." with ππ» 170 00:52:59 Steffi LaZerte (she/her): Replying to "Do you guys load mag..." 171 172 Ohhhhhhh! 173 00:53:04 Howard Baek: Reacted to "Ohhhhhhh!" with π 174 00:55:30 Gabby Palomo Munoz: I found this for the FiraCode Font because if Hadley uses it I want it LOL https://github.com/tonsky/FiraCode/wiki/RStudio-instructions 175 00:56:52 Howard Baek: Replying to "I found this for the..." 176 177 Yes, that is exactly why Iβm using FiraCode 178 00:56:58 Howard Baek: Reacted to "I found this for the..." with π 179 00:57:07 Gabby Palomo Munoz: Reacted to "Yes, that is exactly..." with π 180 00:57:20 Gabby Palomo Munoz: Replying to "I found this for the..." 181 182 Well I am copying you now LOL 183 00:57:27 Howard Baek: Reacted to "Well I am copying yo..." with π 184 00:58:07 Howard Baek: I gotta run everyone, see you all next week!!! 185 00:58:12 Olivier Leroy: Reacted to "I gotta run everyone..." with π 186 00:58:53 Gabby Palomo Munoz: Reacted to "I gotta run everyone..." with π 187 01:07:34 Diana Garcia Cortes: great! Thank you 188 01:07:38 Olivier Leroy: end 189 ``` 190 </details>