Hi,
using the library "stringi" allows this:
> unlist(stringr::str_split(x, "\n"))
[1] "abc" "def" """ghi"
Best,
Kimmo
ke, 2025-02-05 kello 09:35 -0500, Duncan Murdoch kirjoitti:
> Thanks to Rui, Peter and Tanvir! Peter's seems to be the fastest of
> the
> 3 suggestions so far on the littl
On 2025-02-05 5:20 p.m., Rolf Turner wrote:
On Wed, 5 Feb 2025 08:44:12 -0500
Duncan Murdoch wrote:
If I have this object:
x <- c("abc\ndef", "", "ghi")
and I write it to a file using `writeLines(x, "test.txt")`, my text
editor sees a 5 line file:
1: abc
2: def
3:
4: gh
Hello,
Inline.
Às 20:27 de 05/02/2025, peter dalgaard escreveu:
A 3rd option could be
scan(text=x, what="", blank.lines.skip=FALSE)
(all because readLines() doesn't obey the text=x convention, perhaps it should?
I'm unsure whether the textConnection is left open in Rui's method.)
No, it is
On Wed, 5 Feb 2025 08:44:12 -0500
Duncan Murdoch wrote:
> If I have this object:
>
>x <- c("abc\ndef", "", "ghi")
>
> and I write it to a file using `writeLines(x, "test.txt")`, my text
> editor sees a 5 line file:
>
>1: abc
>2: def
>3:
>4: ghi
>5:
>
> which is what
A 3rd option could be
scan(text=x, what="", blank.lines.skip=FALSE)
(all because readLines() doesn't obey the text=x convention, perhaps it should?
I'm unsure whether the textConnection is left open in Rui's method.)
-pd
> On 5 Feb 2025, at 15:35 , Duncan Murdoch wrote:
>
> Thanks to Rui, Pe
Thanks to Rui, Peter and Tanvir! Peter's seems to be the fastest of the
3 suggestions so far on the little test case, but on the real data
(where x contains several thousand lines), Rui's seems best.
Duncan
On 2025-02-05 9:13 a.m., peter dalgaard wrote:
This also seems to work:
strsplit(pa
x <- c("abc\ndef", "", "ghi")
unlist(strsplit(gsub("^$", "\n", x), "\n"))
or
x %>%
gsub("^$", "\n", .) %>%
strsplit("\n") %>%
unlist()
Regards.
Tanvir Ahamed
Stockholm, Sweden | mashra...@yahoo.com
On Wednesday, February 5, 2025 at 02:44:37 PM GMT+1, Duncan Murdoch
This also seems to work:
> strsplit(paste(x,collapse="\n"),"\n")[[1]]
[1] "abc" "def" """ghi"
> On 5 Feb 2025, at 14:44 , Duncan Murdoch wrote:
>
> If I have this object:
>
> x <- c("abc\ndef", "", "ghi")
>
> and I write it to a file using `writeLines(x, "test.txt")`, my text editor
>
Às 13:44 de 05/02/2025, Duncan Murdoch escreveu:
If I have this object:
x <- c("abc\ndef", "", "ghi")
and I write it to a file using `writeLines(x, "test.txt")`, my text
editor sees a 5 line file:
1: abc
2: def
3:
4: ghi
5:
which is what I'd expect: the last line in the e
9 matches
Mail list logo