[Rd] R::Rdconv Rdconv() does not close input file handle (PR#9126)

bill at insightful.com bill at insightful.com
Sat Aug 5 02:01:48 CEST 2006


Full_Name: Bill Dunlap
Version: 2.3.0
OS: Windows XP
Submission from: (NULL) (71.121.183.214)


If you had an Rd file called "file.Rd"
and write a perl script containing
    print "Before Rdconv: " ; system "/usr/sbin/lsof | grep $USER | grep Rd";
    Rdconv("file.Rd", "", "example, "../R-ex/file.R");
    print "After Rdconv: " ; system "/usr/sbin/lsof | grep $USER | grep Rd";
you will see that file.Rd is still open after Rdconv
returns.  This messed up perl script on Windows
where I tried to remove the directory containing
the *.R files after processing them and I could
not remove it because the last file processed was
still open.

Making the following change to RHOME/share/perl/R/Rdconv.pm
seems to fix it.

77,78c77,82
<     open(rdfile, "<$Rdname") or die "Rdconv(): Couldn't open '$Rdname':
$!\n";
<
---
>     open(my $rdfile, "<$Rdname") or die "Rdconv(): Couldn't open '$Rdfile':
$!\n";
>     # Before we added the 'my $' in front of rdfile,
>     # rdfile was not getting closed.   Now it will close
>     # when $rdfile goes out of scope.  (We could have added
>     # a close rdfile at the end of the while(<rdfile>), but
>     # scoping method is more reliable.
123c127
<     while(<rdfile>){
---
>     while(<$rdfile>){

-Bill



More information about the R-devel mailing list