Berry Boessenkool Berry Boessenkool - 1 year ago 57
R Question

What line break does RCurl return on a mac?

returns different line breaks of an ftp directory on Windows and Linux systems.

if(!requireNamespace("RCurl", quietly=TRUE)) install.packages("RCurl")
link <- ""
RCurl::getURL(link, ftp.use.epsv=TRUE, dirlistonly=TRUE)['sysname'] ; .Platform$OS.type

# Windows / windows: "climate\r\nphenology\r\nradiosondes\r\nclimate_urban\r\n"
# Linux / unix: "climate\nphenology\nradiosondes\nclimate_urban\n"

To get a vector of character strings, I can handle both with

p <- strsplit(p, "\n")[[1]]
p <- gsub("\r", "", p) # additional carriage return in windows libcurl

But: it seems that mac may return
only from the eol explanation in In that case, my approach would fail.

Can someone with a mac test and post the mac (['sysname']
: "Darwin") output? How about solaris ("SunOS")?

Answer Source

I would split on all carraige return, with a regex including both and filter empty entries after like this:




Which Gives:

> p
[1] "climate"       "phenology"     "radiosondes"   "climate_urban"
> p1
[1] "climate"       "phenology"     "radiosondes"   "climate_urban"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download