I've tried to create a reprex to the best of my ability. I have to read in a .txt
file and split it using different regular expressions a bunch and would like to save some code. I'm wondering if it is possible to solve this problem using compose()
and partial()
or if I should create a function, the way I'm trying to do it I keep getting an error. For example:
library(tidyverse)
textfile <- "https://byuistats.github.io/M335/data/randomletters.txt"
read_and_split <- compose(partial(str_split, simplify = T),
read_lines)
# I would use it in the following ways
read_and_split(textfile, pattern = "")
#> Error in last(...): unused argument (pattern = "")
read_and_split(textfile, pattern = "[^0-9]+")
#> Error in last(...): unused argument (pattern = "[^0-9]+")
Created on 2019-01-10 by the reprex package (v0.2.1)
Am I going about this the wrong way (trying to spice up my purrr chops) or should I refactor this into a function? I'm pretty sure the technical term regarding this is 'currying' but haven't found many helpful resources explaining how we do it in R (besides the purrr mission statement saying (...) is a replacement for it).