The function reads a text file and tries to detect file encoding. If you have Chinese files from different sources and cannot give them a single encoding, just let this function detect and read them. The function can save you much time on dealing with unrecognizable characters.
scancn(x, enc = "auto", collapse = " ")
a length 1 character specifying filename.
a length 1 character of file encoding specified by user. The default is "auto", which means let the function detect encoding.
this is used by the
The function calls
scan(x, what = "character", ...) and
a Chinese file is encoded in "UTF-8", but what is actually read is a "?". When this happens,
the function reads it twice and uses
stringi::stri_encode to convert it.
If invalid inputs are found in the content, the file will also be read twice.
The function always returns a length 1 character. If the return of
scan is a vector
with length larger than 1,
elements will be pasted together with three spaces
or other specified symbols.
It will return
a " " (one space) when all the elements of the vector are
If not all elements
NA, those equal to
NA will be changed to "" (a size 0 string) before being
a length 1 character of text.
1 2 3
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.