[R-pkg-devel] RTools 4.x Perl Incompatibility with WriteXLS CRAN Package

Ivan Krylov |kry|ov @end|ng |rom d|@root@org
Fri Jul 19 17:18:24 CEST 2024


Dear Marc Schwartz,

В Fri, 19 Jul 2024 10:49:31 -0400
Marc Schwartz <marc_schwartz using me.com> пишет:

> . No such file or
> directory\Kleinbub\AppData\Local\Temp\RtmpuO4911/WriteXLS/1.csv

This looks like an extra carriage return has messed up the output.
By debugging WriteXLS and running the command line manually with perl
-d, I can confirm this:

main::(C:/Users/redacted/AppData/Local/R/win-library/4.5/WriteXLS/Perl/WriteXLS.pl:135):
135:    my @FileNames = "";
  DB<3>
main::(C:/Users/redacted/AppData/Local/R/win-library/4.5/WriteXLS/Perl/WriteXLS.pl:136):
136:    open (DFHANDLE, $Encode, "$CSVPath/FileNames.txt") || die
        "ERROR: cannot open $CSVPath/FileNames.txt. $!\n";
  DB<3>
main::(C:/Users/redacted/AppData/Local/R/win-library/4.5/WriteXLS/Perl/WriteXLS.pl:137):
137:    @FileNames = <DFHANDLE>;
  DB<3>
main::(C:/Users/redacted/AppData/Local/R/win-library/4.5/WriteXLS/Perl/WriteXLS.pl:138):
138:    close DFHANDLE;
  DB<3> x \@FileNames
0  ARRAY(0xa005e3c08)
   0  "C:\\rtools44\\tmp\\Rtmpg9BxFb/WriteXLS/1.csv\cM\cJ"
  DB<4> n
main::(C:/Users/redacted/AppData/Local/R/win-library/4.5/WriteXLS/Perl/WriteXLS.pl:141):
141:    chomp(@FileNames);
  DB<4> n
main::(C:/Users/redacted/AppData/Local/R/win-library/4.5/WriteXLS/Perl/WriteXLS.pl:302):
302:    foreach my $FileName (@FileNames) {
  DB<4> x \@FileNames
0  ARRAY(0xa005e3c08)
   0  "C:\\rtools44\\tmp\\Rtmpg9BxFb/WriteXLS/1.csv\cM"

Since the R code always uses a text-mode connection with WriteLines,
it always results in CR-LF line endings on Windows. The difference must
be in the default PerlIO layers applied by Strawberry Perl by default.
MSYS is based on Cygwin, which does its best to pretend to be an
Unix-like environment, so it's reasonable for an MSYS build of Perl to
default to LF line endings. But that means special-casing the MSYS
build of Perl:

  DB<5> x $Encode
0  '<:encoding(utf8)'
  DB<6> x $^O
0  'msys'

...and adding $Encode .= ":crlf" if $^O eq 'msys'; somewhere.

-- 
Best regards,
Ivan



More information about the R-package-devel mailing list