1 package Statistics::R::Win32;
7 use Env qw( @PATH $PROGRAMFILES );
9 use vars qw{@ISA @EXPORT};
25 Statistics::R::Win32 - Helper functions for Statistics::R on MS Windows platforms
29 B<Do not use this module directly. Use L<Statistics::R> instead.>
31 Helper functions to deal with environment variables and escape file paths on
36 if ( $^O =~ m/^(?:.*?win32|dos)$/i ) {
37 require Statistics::R::Win32;
44 =item win32_path_adjust( )
46 Looks for paths where R could be installed, e.g. C:\Program Files (x86)\R-2.1\bin
47 and add it to the PATH environment variable.
49 =item win32_space_quote( )
51 Takes a path and return a path that is surrounded by double-quotes if the path
52 contains whitespaces. Example:
54 C:\Program Files\R\bin\x64
58 "C:\Program Files\R\bin\x64"
60 =item win32_space_escape( )
62 Takes a path and return a path where spaces have been escaped by a backslash.
63 contains whitespaces. Example:
65 C:\Program Files\R\bin\x64
69 C:\Program\ Files\R\bin\x64
73 Takes a path and return a path where each backslash was replaced by two backslashes.
76 C:\Program Files\R\bin\x64
80 C:\\Program Files\\R\\bin\\x64
88 =item * L<Statistics::R>
94 Florent Angly E<lt>florent.angly@gmail.comE<gt> (2011 rewrite)
96 Graciliano M. P. E<lt>gm@virtuasites.com.brE<gt> (original code)
100 Florent Angly E<lt>florent.angly@gmail.comE<gt>
102 Brian Cassidy E<lt>bricas@cpan.orgE<gt>
104 =head1 COPYRIGHT & LICENSE
106 This program is free software; you can redistribute it and/or
107 modify it under the same terms as Perl itself.
111 All complex software has bugs lurking in it, and this program is no exception.
112 If you find a bug, please report it on the CPAN Tracker of Statistics::R:
113 L<http://rt.cpan.org/Dist/Display.html?Name=Statistics-R>
115 Bug reports, suggestions and patches are welcome. The Statistics::R code is
116 developed on Github (L<http://github.com/bricas/statistics-r>) and is under Git
117 revision control. To get the latest revision, run:
119 git clone git@github.com:bricas/statistics-r.git
124 # Adjust PATH environment variable when this module is loaded.
128 # Find potential R directories in the Windows Program Files folder and
129 # add them to the PATH environment variable.
130 sub win32_path_adjust {
132 # Find potential R directories, e.g. C:\Program Files (x86)\R-2.1\bin
133 # or C:\Program Files\R\bin\x64
135 if (defined $PROGRAMFILES) {
136 push @prog_file_dirs, $PROGRAMFILES; # e.g. C:\Program Files (x86)
137 my ($programfiles_2) = ($PROGRAMFILES =~ m/^(.*) \(/); # e.g. C:\Program Files
138 if ( defined $programfiles_2 and $programfiles_2 ne $PROGRAMFILES ) {
139 push @prog_file_dirs, $programfiles_2;
143 # Append R directories to PATH
148 File::Spec->catdir( $_, 'bin', 'x64' ),
149 File::Spec->catdir( $_, 'bin' ),
152 File::DosGlob::glob( win32_space_escape( win32_double_bs($_) ) )
154 File::Spec->catdir( $_, $PROG, "$PROG-*" ),
155 File::Spec->catdir( $_, "$PROG-*" ),
156 File::Spec->catdir( $_, $PROG ),
165 sub win32_space_quote {
166 # Quote a path if it contains whitespaces
168 $path = '"'.$path.'"' if $path =~ /\s/;
173 sub win32_space_escape {
174 # Escape spaces with a single backslash
181 sub win32_double_bs {
182 # Double the backslashes
184 $path =~ s/\\/\\\\/g;