Twitter | Search | |
This is the legacy version of twitter.com. We will be shutting it down on 15 December 2020. Please switch to a supported browser or device. You can see a list of supported browsers in our Help Center.
We are R-Ladies 29 Aug 18
🐫 Happy Wednesday! In the spirit of 's Lesser Known ⭐️s of the Tidyverse (πŸ“Ή ), today I am going to be sharing some of my favorite tricks!
Reply Retweet Like
We are R-Ladies
☝️ My first tip: use purrr::map_df() to read all .csv files in a πŸ“‚ and stick them in a single data frame: f <- list.files( "my_folder", pattern = "*.csv", full.names = TRUE) d <- purrr::map_df(f, readr::read_csv, .id = "id")
Reply Retweet Like More
We are R-Ladies 29 Aug 18
Replying to @WeAreRLadies
✌️ My second tip: use broom::tidy() πŸ› to get a nice data frame of your model results: m <- lm(mpg ~ qsec + wt, data = mtcars) broom::tidy(m)
Reply Retweet Like
We are R-Ladies 29 Aug 18
Replying to @WeAreRLadies
πŸ‘Œ My third tip: glue ✨ that broom output into some nice sentences for a manuscript: m <- lm(mpg ~ qsec + wt, data = mtcars) t <- broom::tidy(m) glue::glue_data(t, "The point estimate for the {term} term is {round(estimate, 3)} (p-value = {signif(p.value, 2)}).")
Reply Retweet Like
We are R-Ladies 29 Aug 18
Replying to @WeAreRLadies
🀘🀘 My fourth tip: Have a collaborator that would prefer for your documents πŸ“ƒ to be in Word? You can render .Rmd files into Word documents: πŸ‘‰ update your yaml: output: word_document -or- πŸ‘‰rmarkdown::render( "my_document.Rmd", output_format = "word_document")
Reply Retweet Like
We are R-Ladies 29 Aug 18
Replying to @WeAreRLadies
πŸ– My fifth tip: Hate emailing πŸ“§ Word documents back and forth? Send that doc you just knit from your .Rmd file to Google Drive! googledrive::drive_upload( β€œmy_document.docx”, type = β€œdocument”)
Reply Retweet Like
We are R-Ladies 29 Aug 18
Replying to @yoniceedee
😎 Final (meta) tip: Create clean code images using 's carbonate πŸ“¦ ☝️ Copy code you'd like to share to your clipboard πŸ“‹ ✌️ Run this code to generate the image and view it in your browser x <- carbonate::carbon$new() x$browse() πŸ”—
Reply Retweet Like
We are R-Ladies 29 Aug 18
Replying to @yoniceedee
πŸ—£ What are YOUR favorite tips and tricks?
Reply Retweet Like
Henning 29 Aug 18
Replying to @WeAreRLadies
Pipe it! :)
Reply Retweet Like
We are R-Ladies 29 Aug 18
Replying to @henningsway
The pipe really does always make things look prettier πŸ˜πŸ’…
Reply Retweet Like
Jana B Jarecki 29 Aug 18
Thanks! Regarding the first tip: try the one-liner library(data.table) rbindlist(lapply(list.files("my folder", pattern="*.csv", full.names=T), fread) fread is extremely fast for many and/or big files and no need to specify separators...
Reply Retweet Like
Ross Holmberg 30 Aug 18
Agreed. I feel like I use this nearly daily. Although my preferred syntax (`data.table` and `magrittr` both required) looks like: files <- list.files() dt <- lapply( files, fread ) %>% setNames ( files ) %>% rbindlist( idcol = "file" )
Reply Retweet Like