X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sweavealike.pm;h=c3dad531655181ce6a0a9dcb8fef7e24e9a52fd7;hb=ac8df1a32dedb724c0a3e38387a2e8912bd5e954;hp=16713a0092c64e57b0447872612caf093acd2c07;hpb=0480a392d8eb5ff892dcf71f293d86d2f51a32c6;p=ikiwiki_plugins.git
diff --git a/sweavealike.pm b/sweavealike.pm
index 16713a0..c3dad53 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
@@ -124,7 +130,7 @@ sub preprocess {
error("There wasn't any R code supplied");
}
- my $image_loc
+ my $image_loc = '';
if (exists $param{fig}) {
$param{width} = '400' unless exists $param{width} and defined $param{width};
$param{height} = '400' unless exists $param{height} and defined $param{height};
@@ -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;
@@ -164,7 +172,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);
@@ -176,14 +184,14 @@ sub preprocess {
}
if (not exists $param{results} or
(defined $param{results} and
- $param{results} !~ /^(hide|false)$/i;)) {
+ $param{results} !~ /^(hide|false)$/i)) {
$output .= $code_result;
}
if (exists $param{echo} or
exists $param{results}) {
$output =~ s/^/ /mg;
}
- return($output);
+ return($output.$fig_output);
}
# stop any started R processes here
@@ -204,12 +212,12 @@ sub savestate {
# make sure we never try to save an R process
for my $page (keys %pagestate) {
next unless exists $pagestate{$page}{$id};
- next unless ;
if (exists $pagestate{$page}{$id}{R}) {
if (defined $pagestate{$page}{$id}{R}
and $pagestate{$page}{$id}{R}->is_started()) {
$pagestate{$page}{$id}{R}->stop;
}
+ delete $pagestate{$page}{$id}{R};
}
if (exists $pagestate{$page}{$id}{fignum}) {
delete $pagestate{$page}{$id}{fignum}