[R] Problem related to multibyte string in CSV file
Dennis Fisher
||@her @end|ng |rom p|e@@th@n@com
Thu Nov 14 18:34:30 CET 2019
R 3.6.1
OS X
Colleagues,
I read the first line of a CSV file using the readLines command; the only option was n=1 (I am interested in only the first line of the file)
STRING <- readLines(FILE, n=1)
to which R responded:
Warning message:
In readLines(FILE, n = 1) : line 1 appears to contain an embedded nul
I then attempted to determine the number of characters in that string:
nchar(STRING)
to which R responded:
Error in nchar(STRING) : invalid multibyte string, element 1
I then went to examine the string:
print(STRING)
[1] "\xff\xfet”
and:
cat(STRING, "\n”)
??t
I was surprised to see the difference in the output of cat vs. string (see above). But I assume this results from the multibyte characters.
Now to my question: I am trying to automate this process and I would like to see the output from the print command but without the [1] that precedes the string.
If I am working at the command line, RGUI, or RStudio, I can type
STRING<CR>
However, in a script, I need to preface STRING with either “print” or “cat” (or something else).
Short of writing my own print method, is there any simple way to accomplish this?
Dennis
Dennis Fisher MD
P < (The "P Less Than" Company)
Phone / Fax: 1-866-PLessThan (1-866-753-7784)
www.PLessThan.com
More information about the R-help
mailing list