-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update write function ( utf8 encoding) #224
Conversation
Codecov Report
@@ Coverage Diff @@
## master #224 +/- ##
==========================================
- Coverage 56.76% 52.51% -4.25%
==========================================
Files 42 42
Lines 1663 1449 -214
==========================================
- Hits 944 761 -183
+ Misses 719 688 -31
Continue to review full report at Codecov.
|
R/zzz.r
Outdated
|
||
|
||
write_utf8 = function(text, con, ...) { | ||
if (identical(con, '')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lchiffon I'm curious, why this first if block part with cat()
? As far as I remember, the user can't pass in a path, so path
should always be NULL
in which case tmpf
will be output of tempfile("elastic__")
. Or am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sckott This function write_utf8
a replacement of writeLines
in most of UTF-8 situation.
Actually, I forked it from yihui's xfun
package:
https://github.com/yihui/xfun/blob/6eb610da9203565b7d3342ea5dc84b7ab143f206/R/io.R#L29
To minimize the dependency, I didn't add this package to import.
Do you think we should delete this block part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. I think we can remove the cat()
part since we shouldn't ever need that. So just:
write_utf8 = function(text, con, ...) {
# prevent re-encoding the text in the file() connection in writeLines()
# https://kevinushey.github.io/blog/2018/02/21/string-encoding-and-r/
opts = options(encoding = 'native.enc'); on.exit(options(opts), add = TRUE)
writeLines(enc2utf8(text), con, ..., useBytes = TRUE)
}
thanks for this! |
fix encoding write function in UTF-8
Related Issue
#223
Example