Skip to content

Commit

Permalink
#317: Using temporary file for the install script in install_via_r_re…
Browse files Browse the repository at this point in the history
…motes (#204)

The previous version of the script failed when the dependency list was too long, because it passed the generated install R script via command line to Rscript.
  • Loading branch information
tkilias authored Aug 12, 2021
1 parent 12dadeb commit 100fc4f
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions ext/scripts/install_scripts/install_via_r_remotes.pl
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ =head1 SYNOPSIS
}


my $combining_template = "$rscript_binary -e 'library(remotes);<<<<0>>>>'";
my @separators = (";");
my @templates = ('install_version("<<<<0>>>>",,repos="http://cran.r-project.org")');
my $combining_template = "library(remotes)\n<<<<0>>>>";
my @separators = ("\n");
my @templates = ('install_version("<<<<0>>>>",NULL,repos="http://cran.r-project.org")');
if($with_versions){
@templates = ('install_version("<<<<0>>>>","<<<<1>>>>",repos="http://cran.r-project.org")');
}
Expand All @@ -78,17 +78,26 @@ sub replace_missing_version{
@rendered_line_transformation_functions = (\&replace_missing_version);
}

my $cmd =
my $script =
package_mgmt_utils::generate_joined_and_transformed_string_from_file(
$file,$element_separator,$combining_template,\@templates,\@separators,\@rendered_line_transformation_functions);

if($with_versions and not $allow_no_version){
if (index($cmd, "<<<<1>>>>") != -1) {
die "Command '$cmd' contains packages with unspecified versions, please check the package file '$file' or specifiy --allow-no-version";
if (index($script, "<<<<1>>>>") != -1) {
die "Command '$script' contains packages with unspecified versions, please check the package file '$file' or specifiy --allow-no-version";
}
}

if($cmd ne ""){


if($script ne ""){
my $filename = "/tmp/install_packages_via_remotes.r";
open(FH, '>', $filename) or die $!;
print FH $script;
close(FH);
my $cmd = "$rscript_binary '$filename'";
package_mgmt_utils::execute("$rscript_binary -e 'install.packages(\"remotes\",repos=\"http://cran.r-project.org\")'",$dry_run);
print "Executing:\n$script\n";
package_mgmt_utils::execute($cmd,$dry_run);
unlink($filename) or die "Can't delete $filename: $!\n";
}

0 comments on commit 100fc4f

Please sign in to comment.