I am working in R that invokes linux commands.
This is my code:
system2("wc", args = c("-l",(paste0(" ", file1),stdout = TRUE))
I need to save the word count value to a variable and call it in R. How can I do that?
I am working in R that invokes linux commands.
This is my code:
system2("wc", args = c("-l",(paste0(" ", file1),stdout = TRUE))
I need to save the word count value to a variable and call it in R. How can I do that?
Your approach seems to be correct, but check your parentheses:
file1 <- tempfile()
cat("There are seven words in this sentence.", file = file1)
count <- system2("wc", args = c("-w", file1), stdout = TRUE)
as.numeric(sub(file1, "", count))
# [1] 7
"-w" to "-l"?