I have the following code:
myFunction.R
myFunction({
lorem <- "ipsum"
...
print("dolor sit amet")
})
myFunction({
consectetur <- "adipiscing elit"
...
sed <- paste("do", "eiusmod")
})
...
In another R script, I would like to extract all myFunction calls. Right now the best that I came up with was:
library(stringr)
library(readtext)
script <- readtext('myFunction.R')[['text']]
matches <- str_extract_all(script, 'myFunction(.|\\n)*\\}\\)')[[1]]
But unfortunately, matches contain the first myFunction call until the end of the file. How can I improve the RegEx to match only each myFunction call?