Skip Menu |

This queue is for tickets about the Statistics-R CPAN distribution.

Report information
The Basics
Id: 6724
Status: resolved
Priority: 0/
Queue: Statistics-R

People
Owner: Nobody in particular
Requestors: sato-fu [...] is.naist.jp
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Unexpected change of current directory
Script's current directory is changed in the $R->startR() function. I think this behavior is not good, as a module. It is better to save a original current directory and get it back internally. I faced this problem on Linux + perl 5.8.1. --- use Statistics::R; print `pwd`; my $R = Statistics::R->new() ; $R->startR(); $R->stopR(); print `pwd`; # show different directory --- --- use Statistics::R; use Cwd; print `pwd`; my $cwd = getcwd(); my $R = Statistics::R->new() ; $R->startR(); $R->stopR(); chdir($cwd); print `pwd`; # no problem ---
I agree with the report above. In my case, this unexpected change of current directory has created a hard to debug problem. Unless it is unavoidable, it would be nice if Statistics::R did not change the working directory. At the moment, I work around this change of current directory issueby setting the log_dir option to the current directory: use Cwd; use Statistics::R; print "Location before: ".cwd."\n"; my $R = Statistics::R->new( log_dir => cwd ); $R->startR(); $R->stopR(); print "Location after: ".cwd."\n"; # location should be unchanged It seems like the code starting at line 302 of lib/Statistics/R/Bridge.pm is responsible for the change of directory: my $cmd = "$this->{START_CMD} <start.r >output.log"; chdir( "$this->{LOG_DIR}" ); my $pid = open( my $read, "| $cmd" ); return if !$pid; Probably, replacing the name of files such as start.r and output.log by their fully qualified name, i.e. File::Spec::catfile($this->{LOG_DIR}, 'output.log') would prevent having to change from the current directory to the log directory.
The workaround I presented above is not good because it triggers bug 70392: https://rt.cpan.org/Ticket/Display.html?id=70392&results=d7d740ac826e5c948d56c3761e4de9d7
I have fixed this in version 0.10.
Resolved