ときどきの雑記帖 RE* (新南口)
戦国自衛隊
RSS
今更RSS置くようにしましたっても需要も何もあったもんじゃないとは思いますが、 Hugo の機能でRSSのデータも作られるのでトップページと同じところに置いています。
HTML中ではこんな感じに。
<link href="./index.xml" rel="alternate" type="application/rss+xml" title="ときどきの雑記帖 Re*" />
<link href="./index.xml" rel="feed" type="application/rss+xml" title="ときどきの雑記帖 Re*" />
RSSに吐かれる内容やら範囲を指定するのはどうやんのかね。調べておこう。
R
朗報! R 4.0.3からはcmdやPowerShellでRを起動しても文字化けしない - Qiita
という記事を見かけ、手元に4.0.2が入っていたので試してみたところこれでもちゃんと動いた。
Rterm now correctly displays multi-byte-coded characters representable in the current native encoding (at least on Windows 10 they were sometimes omitted, PR#17632).
は R: R News の後ろの方、
[R logo] CHANGES IN R 4.0.0
よりも後にあったので、4.0.0の時点で入った修正じゃないですかね。
実際、17632 – In Windows shell, Korean characters are not displayed at all. のやり取りをみても
Tomas Kalibera 2019-11-12 16:29:17 UTC
I was able to reproduce on my system, the problem happens also for characters representable in the current native encoding, and hence it is a bug. The initial license information when R starts is printed using Rprintf(), which uses TRIO library on Windows, which emits characters byte-by-byte, which in turn does not work for multi-byte characters. The “Save image” question is instead displayed using getline(), which writes the complete string at once, so does not split multi-byte characters. I’ve fixed this in R-devel in the R copy of TRIO (77405), it now also writes the complete string at once. I’m adding a screenshot with the current output in R-devel.
Tomas Kalibera 2019-11-12 16:30:25 UTC
Created attachment 2486 [details] After the fix in R-devel 77405.
と、ほぼ一年前に解決している話ではある。
実はこの問題ちょっとだけ自分も追いかけたことがあったのだけど(ここで書いていたかもしれない)、 原因をつかみきれなくて途中で止めちゃってたりする。
さて、TRIOってライブラリに問題があったように読めたのでその辺に絞って3.6.3と4.0.0のdiffを 取ってみる。
diff -u "R-3.6.3/src/extra/trio/trio.c" "R-4.0.0/src/extra/trio/trio.c"
--- "R-3.6.3/src/extra/trio/trio.c" 2018-09-25 17:46:45.000000000 +0900
+++ "R-4.0.0/src/extra/trio/trio.c" 2020-03-27 08:02:30.000000000 +0900
@@ -1,4 +1,6 @@
/* Modified for R to support round-to-even */
+/* Modified for R to buffer printf/fprintf output before printing to avoid
+ problems with multi-byte characters */
先頭にこんなコメントが追加されていたので修正はこのファイルだろう。
で、この関数が修正のメインのようだ。
@@ -4095,6 +4096,80 @@
#endif /* TRIO_FEATURE_DYNAMICSTRING */
/*************************************************************************
+ * TrioFormatFile
+ *
+ * a version of TrioFormat modified for R. Writes to a file or file
+ * descriptor, but via a single call, not by-byte, because that does
+ * not work with multi-byte coded characters.
+ *
+ */
+TRIO_PRIVATE int
+TrioFormatFile
+TRIO_ARGS6((destination, destinationSize, OutStream, format, arglist, argarray),
+ trio_pointer_t destination,
+ size_t destinationSize,
+ void (*OutStream) TRIO_PROTO((trio_class_t *, int)),
+ TRIO_CONST char *format,
+ va_list arglist,
+ trio_pointer_t *argarray)
+{
+ int status;
+ trio_class_t data;
+ trio_parameter_t parameters[MAX_PARAMETERS];
+ trio_string_t *info = trio_xstring_duplicate("");
+ if (!info)
+ return TRIO_ERROR_RETURN(TRIO_ENOMEM, 0);
+
+ assert(VALID(OutStream));
+ assert(VALID(format));
+
+ memset(&data, 0, sizeof(data));
+ data.OutStream = TrioOutStreamStringDynamic;
+ data.location = info;
+ data.max = 0;
+ data.error = 0;
+
+#if defined(USE_LOCALE)
+ if (NULL == internalLocaleValues)
+ {
+ TrioSetLocale();
+ }
+#endif
+
+ status = TrioParse(TYPE_PRINT, format, parameters, arglist, argarray);
+ if (status < 0)
+ return status;
+
+ status = TrioFormatProcess(&data, format, parameters);
+ if (status >= 0)
+ {
+ trio_string_terminate(info);
+ char *result = trio_string_extract(info);
+ trio_string_destroy(info);
+ assert(VALID(destination));
+ if (OutStream == TrioOutStreamFile) {
+ FILE *file = (FILE *)destination;
+ size_t written = fwrite(result, 1, status, file);
+ if (written < status) {
+ data.error = TRIO_ERROR_RETURN(TRIO_ERRNO, 0);
+ status = (int) written;
+ }
+#if TRIO_FEATURE_FD
+ } else if (OutStream == TrioOutStreamFileDescriptor) {
+ assert(0); /* not implemented - not used by R */
+#endif
+ } else
+ assert(0);
+ TRIO_FREE(result);
+ }
+ if (data.error != 0)
+ {
+ status = data.error;
+ }
+ return status;
+}
+
+/*************************************************************************
*
* Formatted printing functions
*
そう言えばコマンドプロンプトで、マルチバイト文字を上位バイト下位バイトに分けて二回で出力すると
結果は期待通りにならないってのがあったような > not by-byte, because that does not work with multi-byte coded characters.
Qiita の記事では対話環境の入力での表示がまだおかしいという記述があるけど それはまあそうかもしれない。この修正だけならば(要確認)。