Skip to content

Instantly share code, notes, and snippets.

@yatsuta
Created August 10, 2016 17:18
Show Gist options
  • Save yatsuta/ced1ccc7cab71e50aaa55ba7acdf3b10 to your computer and use it in GitHub Desktop.
Save yatsuta/ced1ccc7cab71e50aaa55ba7acdf3b10 to your computer and use it in GitHub Desktop.
patch for R UTF8 problem of c function
--- bind.c.backup 2016-08-10 19:52:17.000000000 +0900
+++ bind.c 2016-08-11 01:24:41.000000000 +0900
@@ -496,6 +496,7 @@ static SEXP NewBase(SEXP base, SEXP tag)
/* This isn't strictly correct as we do not know that all the
components of the name were correctly translated. */
ans = mkCharCE(cbuf, CE_UTF8);
+ if (!ENC_KNOWN(base)) ans = mkCharCE(translateChar(ans), CE_NATIVE);
vmaxset(vmax);
}
else if (*CHAR(tag)) {
@@ -528,6 +529,7 @@ static SEXP NewName(SEXP base, SEXP tag,
cbuf = R_AllocStringBuffer(strlen(sb) + strlen(st) + 1, &cbuff);
sprintf(cbuf, "%s.%s", sb, st);
ans = mkCharCE(cbuf, CE_UTF8);
+ if (!ENC_KNOWN(base)) ans = mkCharCE(translateChar(ans), CE_NATIVE);
}
else if (*CHAR(base)) {
const char *sb = translateChar(base);
@@ -535,6 +537,7 @@ static SEXP NewName(SEXP base, SEXP tag,
&cbuff);
sprintf(cbuf, "%s%d", sb, seqno);
ans = mkCharCE(cbuf, CE_UTF8);
+ if (!ENC_KNOWN(base)) ans = mkCharCE(translateChar(ans), CE_NATIVE);
}
else if (*CHAR(tag)) {
if(tag == NA_STRING) ans = NA_STRING;
@@ -543,6 +546,7 @@ static SEXP NewName(SEXP base, SEXP tag,
cbuf = R_AllocStringBuffer(strlen(st), &cbuff);
sprintf(cbuf, "%s", st);
ans = mkCharCE(cbuf, CE_UTF8);
+ if (!ENC_KNOWN(tag)) ans = mkCharCE(translateChar(ans), CE_NATIVE);
}
}
else ans = R_BlankString;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment