[R] Potential Bug: file.show does not support double-byte characters in the file path

Tim t|myu @end|ng |rom protonm@||@com
Thu Jun 17 13:42:48 CEST 2021


Hi,

I may have come across a bug regarding the file.show function in the base package.

### Bug Description

file.show does not support double-byte characters in the file path.

### Platform Info

> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936 LC_CTYPE=Chinese (Simplified)_China.936
[3] LC_MONETARY=Chinese (Simplified)_China.936 LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.936

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] compiler_4.1.0 tools_4.1.0

### Steps to Reproduce

1. Install R-4.1.0 for Windows on Windows 10 x64 21H1 (Chinese-Simplified, zh-CN)
2. Open RGui
3. Create a file named "test.txt" under "C:\Test", so that the full file path does not include double-byte characters
4. Create a file named "test.txt" under "C:\测试", so that the full file path includes double-byte characters
5. Run the following commands in the console
> t1 = "C:\\Test\\test.txt"
> t1
[1] "C:\\Test\\test.txt"
> file.show(t1)
>
> t2 = "C:\\测试\\test.txt"
> t2
[1] "C:\\测试\\test.txt"
> file.show(t2)
Warning message:
In file.show(t2) : file.show(): file 'C:\测试\test.txt' does not exist

Actual Result:

file.show() can correctly open the "C:\Test\test.txt" as the file path does not contain double-byte characters, but it fails to do so for "C:\测试\test.txt".

### Additional information

For users with usernames that include double-byte characters, this bug even prevents demo() from functioning properly.

> demo()
Warning message:
In file.show(outFile, delete.file = TRUE, title = paste("R", tolower(x$title))) :
file.show():不存在'C:\Users\娴嬭瘯涓瓇1\AppData\Local\Temp\RtmpGuWTun\RpackageIQR197068c75431'这个文件

file.show() can correctly read from files containing double-byte characters if the file paths do not. For example, the content for "C:\Test\test.txt" can be "Testing 123 测试". file.show("C:\\Test\\test.txt") would open this file and display its content correctly without specifying the encoding parameter.

Thanks,
Tim
	[[alternative HTML version deleted]]



More information about the R-help mailing list