From beb5a272449df826cc45fea2143e9eff1ba7c10b Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Thu, 22 Mar 2012 13:30:31 -0700 Subject: [PATCH] chdir to the source directory before starting R make sure the destination figure exists --- sweavealike.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sweavealike.pm b/sweavealike.pm index 96bb556..48c603c 100644 --- a/sweavealike.pm +++ b/sweavealike.pm @@ -85,6 +85,7 @@ use IkiWiki '3.00'; use Encode qw(decode); use Digest::MD5 qw(md5_hex); +use Cwd; my $id = "sweavealike"; sub import { @@ -112,8 +113,13 @@ sub preprocess { my %param = @_; if (not defined $pagestate{$param{page}}{$id}{R}) { + # I've decided to put R into the src directory instead of the + # dest directory + my $cur_dir = getcwd; + chdir($config{srcdir}); $pagestate{$param{page}}{$id}{R} = Statistics::R->new(shared => 1) or error("Unable to create an R process"); + chdir($cur_dir); } # we currently don't bother to support anything but outputing the # entire segment of code and its R output @@ -141,11 +147,13 @@ sub preprocess { my $image_loc_esc = $image_loc; $image_loc_esc =~ s/"/\\"/g; will_render($param{page},$image_loc); + # this makes sure that we can write to the file result + writefile($image_loc, $config{destdir}, ""); eval { - $pagestate{$param{page}}{$id}{R}->run(qq|png(filename="$image_loc_esc",width=$param{width},height=$param{height});|); + $pagestate{$param{page}}{$id}{R}->run(qq|png(filename="$config{destdir}/$image_loc_esc",width=$param{width},height=$param{height});|); }; if ($@) { - error(qq|code 'png(filename="$image_loc_esc",width=$param{width},height=$param{height});' (from internal figure handling) produced error '$@'|); + error(qq|code 'png(filename="$config{destdir}/$image_loc_esc",width=$param{width},height=$param{height});' (from internal figure handling) produced error '$@'|); } } my $code_result; -- 2.39.2