X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sweavealike.pm;h=0dd0e1b5ed8260650c629908cf66b7c983f61a89;hb=HEAD;hp=96bb5564c8aaceef08337a911792503759b7dfca;hpb=ed39926a77066179afaa4ea4a429a11ab8ed73cc;p=ikiwiki_plugins.git diff --git a/sweavealike.pm b/sweavealike.pm index 96bb556..0dd0e1b 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,15 @@ 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"); + $pagestate{$param{page}}{$id}{R}->start() or + error("Unable to start the 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 +149,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; @@ -164,7 +174,7 @@ sub preprocess { if ($@) { error("code 'dev.off()' (from internal figure handling) produced error '$@'"); } - $fig_output = qq(\n); + $fig_output = qq(\n\n\n); } if (exists $param{nooutput}) { return($output.$fig_output); @@ -183,7 +193,7 @@ sub preprocess { exists $param{results}) { $output =~ s/^/ /mg; } - return($output); + return($output.$fig_output); } # stop any started R processes here