* [babel] suggestion: wrap creation of graphics into try() block @ 2014-01-20 13:36 Rainer M Krug 2014-01-20 14:00 ` Andreas Leha 0 siblings, 1 reply; 11+ messages in thread From: Rainer M Krug @ 2014-01-20 13:36 UTC (permalink / raw) To: emacs orgmode-mailinglist -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi I have two suggestions which are liked to each other. They are based on R code blocks, but the should be useful for other languages as well. I have a document in which I use :session for creating R graphs. These look like: #+begin_src R :file Correlation_1.pdf :results graphics IFN.mean <- load.IFN.mean() grid <- load.grid.CASTANEA.average() image(IFN.mean) #+end_src Everything works fine, unless there is an error in one graph. In this case, the device remains open, which leaves open devices at the end of the export of the document. If the code block which should create the graph would be wrapped into a try() block, so that it would look like the following: try( { pdf("./Correlation_1.pdf") IFN.mean <- load.IFN.mean() grid <- load.grid.CASTANEA.average() image(IFN.mean) } ) dev.off() The device would be closed even if an error occurred during the execution of the code. But still, when exporting to pdf, the call to pdflatex fails as only a empty pdf is available. So it becomes necessary to go through the pdf log to identify the graphs which failed. In this case it would be useful, to have a placeholder grah in the final pdf, so that one can see which graphs did not work. In addition, this could be used as placeholders (well - they are placeholders) for to be created graphs, while the text has already been written. So my second suggestion would be to include a placeholder image, which would be used if the generation of the actual graph fails. It would be great (but not necessary) if the actual error message would be in the image. Cheers, Rainer - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 59 98 Fax : +33 - (0)9 58 10 27 44 Fax (D): +49 - (0)3 21 21 25 22 44 email: Rainer@krugs.de Skype: RMkrug -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJS3SZgAAoJENvXNx4PUvmCOwQIAKEZuXPy2m8fB05i+h/5KOt6 xxXY+B8AWbBuCj7vtxeSgoXATE3mN6PYIitIqamwnlbb0aeenS8O9T4LOKo/msen 1jvOaSjwtllDTITY4XjNpD6nEp+3Ypheih1OjRWAQh/rozA55ZTmprVoo7ZnwFY/ SQYttaTeJHGws4GzjUBqLBcJwFSshNs3zcygobrFB06FACzLV1lfSLsVQMl6m+Sh g5Ycs7SG6DuKou5HE5QNxw/0RQerMqM78HOCmqhn2bmrE9emnXaz/nNWA6LX/Mnx A4T6Y0rY0t3A6TRCTRyUbSnAbx1MGPz37WxQZmqTIkv8M7xldOxFin4LTwihgBQ= =y+do -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [babel] suggestion: wrap creation of graphics into try() block 2014-01-20 13:36 [babel] suggestion: wrap creation of graphics into try() block Rainer M Krug @ 2014-01-20 14:00 ` Andreas Leha 2014-01-20 15:13 ` Rainer M Krug 0 siblings, 1 reply; 11+ messages in thread From: Andreas Leha @ 2014-01-20 14:00 UTC (permalink / raw) To: emacs-orgmode Rainer M Krug <Rainer@krugs.de> writes: > Hi > > I have two suggestions which are liked to each other. They are based > on R code blocks, but the should be useful for other languages as well. > > I have a document in which I use :session for creating R graphs. These > look like: > > #+begin_src R :file Correlation_1.pdf :results graphics > IFN.mean <- load.IFN.mean() > grid <- load.grid.CASTANEA.average() > image(IFN.mean) > #+end_src > > Everything works fine, unless there is an error in one graph. > > In this case, the device remains open, which leaves open devices at > the end of the export of the document. I experience the same problem. And would love to see that addressed. > > If the code block which should create the graph would be wrapped into > a try() block, so that it would look like the following: > > try( > { > pdf("./Correlation_1.pdf") > IFN.mean <- load.IFN.mean() > grid <- load.grid.CASTANEA.average() > image(IFN.mean) > } > ) > dev.off() > > The device would be closed even if an error occurred during the > execution of the code. > > But still, when exporting to pdf, the call to pdflatex fails as only > a empty pdf is available. So it becomes necessary to go through the > pdf log to identify the graphs which failed. > > In this case it would be useful, to have a placeholder grah in the > final pdf, so that one can see which graphs did not work. > > In addition, this could be used as placeholders (well - they are > placeholders) for to be created graphs, while the text has already > been written. > > So my second suggestion would be to include a placeholder image, which > would be used if the generation of the actual graph fails. It would be > great (but not necessary) if the actual error message would be in the > image. Such an place holder image would be great, indeed. Thanks for bringing this up! Regards, Andreas ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [babel] suggestion: wrap creation of graphics into try() block 2014-01-20 14:00 ` Andreas Leha @ 2014-01-20 15:13 ` Rainer M Krug 2014-01-20 15:28 ` Eric Schulte 0 siblings, 1 reply; 11+ messages in thread From: Rainer M Krug @ 2014-01-20 15:13 UTC (permalink / raw) To: Andreas Leha, emacs-orgmode -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 01/20/14, 15:00 , Andreas Leha wrote: > Rainer M Krug <Rainer@krugs.de> writes: > >> Hi >> >> I have two suggestions which are liked to each other. They are >> based on R code blocks, but the should be useful for other >> languages as well. >> >> I have a document in which I use :session for creating R graphs. >> These look like: >> >> #+begin_src R :file Correlation_1.pdf :results graphics IFN.mean >> <- load.IFN.mean() grid <- load.grid.CASTANEA.average() >> image(IFN.mean) #+end_src >> >> Everything works fine, unless there is an error in one graph. >> >> In this case, the device remains open, which leaves open devices >> at the end of the export of the document. > > I experience the same problem. And would love to see that > addressed. Just checked in the code from ob-R.el, and it should not be to difficult: The functions org-babel-R-construct-graphics-device-call and org-babel-expand-body:R would be affected. I changed : ... Trying it out ... This seems to be working - I just changed it and it closes the device. But further tests are needed. I will leave it to see if anything unexpected happens. If somebody could look if this makes sense? (defun org-babel-expand-body:R (body params &optional graphics-file) "Expand BODY according to PARAMS, return the expanded body." (let ((graphics-file (or graphics-file (org-babel-R-graphical-output-file params)))) (mapconcat #'identity (let ((inside (append (when (cdr (assoc :prologue params)) (list (cdr (assoc :prologue params)))) (org-babel-variable-assignments:R params) (list body) (when (cdr (assoc :epilogue params)) (list (cdr (assoc :epilogue params))))))) (if graphics-file (append (list (org-babel-R-construct-graphics-device-call graphics-file params)) inside ;; my edits (list "},error=function(e){plot(-1:1, -1:1, type='n'); text(0,0,'DUMMY')}); dev.off()")) inside)) ;; end "\n"))) and (format "%s(%s=\"%s\"%s%s%s); tryCatch({" device filearg out-file args (if extra-args "," "") (or extra-args "")))) in org-babel-R-construct-graphics-device-call It is working with the Dummy. Could somebody please check if this is working? I am leaving my changes and will see during my work if it is fine. Cheers, Rainer > >> >> If the code block which should create the graph would be wrapped >> into a try() block, so that it would look like the following: >> >> try( { pdf("./Correlation_1.pdf") IFN.mean <- load.IFN.mean() >> grid <- load.grid.CASTANEA.average() image(IFN.mean) } ) >> dev.off() >> >> The device would be closed even if an error occurred during the >> execution of the code. >> >> But still, when exporting to pdf, the call to pdflatex fails as >> only a empty pdf is available. So it becomes necessary to go >> through the pdf log to identify the graphs which failed. >> >> In this case it would be useful, to have a placeholder grah in >> the final pdf, so that one can see which graphs did not work. >> >> In addition, this could be used as placeholders (well - they are >> placeholders) for to be created graphs, while the text has >> already been written. >> >> So my second suggestion would be to include a placeholder image, >> which would be used if the generation of the actual graph fails. >> It would be great (but not necessary) if the actual error >> message would be in the image. > > Such an place holder image would be great, indeed. > > > Thanks for bringing this up! > > Regards, Andreas > > - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 59 98 Fax : +33 - (0)9 58 10 27 44 Fax (D): +49 - (0)3 21 21 25 22 44 email: Rainer@krugs.de Skype: RMkrug -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJS3T00AAoJENvXNx4PUvmCZt0H/2bfO6rKpB3i5R8RiVMk0Vjc f6N6gnE/kZJNvOj+xtDpesrX2XtAnPzhkeB36LN+uFp2gjObtutwcnsPzOXsUI5g Tamgajk7igafGVJAMWFPDPLXlBu7ayo0AC/NGKrxzjhXIpAGFBi50J4w8nhLXL6l e9k7ovt8yp+uhBLs6X/VI5M3Cph9RU9bcBxkDYWceXz2k4SXesWZZpmJW57okRge yC72SHF2Depkg8PaBHLk75FeAQaZYn1bhnjEwlLKYR7XWGLrIuVCgGuN4ttC0y+F by9t9wvs+uqnP7rG/kYDnkcxHxyVaVJEcUYaELeWiOnrd9R+GZlWY6JADax/BcQ= =x+U0 -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [babel] suggestion: wrap creation of graphics into try() block 2014-01-20 15:13 ` Rainer M Krug @ 2014-01-20 15:28 ` Eric Schulte 2014-01-20 17:02 ` Rainer M Krug 0 siblings, 1 reply; 11+ messages in thread From: Eric Schulte @ 2014-01-20 15:28 UTC (permalink / raw) To: Rainer; +Cc: Andreas Leha, emacs-orgmode Rainer M Krug <Rainer@krugs.de> writes: > On 01/20/14, 15:00 , Andreas Leha wrote: >> Rainer M Krug <Rainer@krugs.de> writes: >> >>> Hi >>> >>> I have two suggestions which are liked to each other. They are >>> based on R code blocks, but the should be useful for other >>> languages as well. >>> >>> I have a document in which I use :session for creating R graphs. >>> These look like: >>> >>> #+begin_src R :file Correlation_1.pdf :results graphics IFN.mean >>> <- load.IFN.mean() grid <- load.grid.CASTANEA.average() >>> image(IFN.mean) #+end_src >>> >>> Everything works fine, unless there is an error in one graph. >>> >>> In this case, the device remains open, which leaves open devices >>> at the end of the export of the document. >> >> I experience the same problem. And would love to see that >> addressed. > > Just checked in the code from ob-R.el, and it should not be to difficult: > > The functions > org-babel-R-construct-graphics-device-call > and > org-babel-expand-body:R > > would be affected. > > I changed : > > > > ... Trying it out ... > > This seems to be working - I just changed it and it closes the device. > But further tests are needed. I will leave it to see if anything > unexpected happens. > Sounds great. When you're confident that this is working please submit a patch and I'll be happy to apply it. Thanks, > > If somebody could look if this makes sense? > (defun org-babel-expand-body:R (body params &optional graphics-file) > "Expand BODY according to PARAMS, return the expanded body." > (let ((graphics-file > (or graphics-file (org-babel-R-graphical-output-file params)))) > (mapconcat > #'identity > (let ((inside > (append > (when (cdr (assoc :prologue params)) > (list (cdr (assoc :prologue params)))) > (org-babel-variable-assignments:R params) > (list body) > (when (cdr (assoc :epilogue params)) > (list (cdr (assoc :epilogue params))))))) > (if graphics-file > (append > (list (org-babel-R-construct-graphics-device-call > graphics-file params)) > inside > ;; my edits > (list "},error=function(e){plot(-1:1, -1:1, type='n'); > text(0,0,'DUMMY')}); dev.off()")) > inside)) > ;; end > "\n"))) > > > > and > > (format "%s(%s=\"%s\"%s%s%s); tryCatch({" > device filearg out-file args > (if extra-args "," "") (or extra-args "")))) > > in org-babel-R-construct-graphics-device-call > > It is working with the Dummy. > > Could somebody please check if this is working? > > I am leaving my changes and will see during my work if it is fine. > > Cheers, > > Rainer > > >> >>> >>> If the code block which should create the graph would be wrapped >>> into a try() block, so that it would look like the following: >>> >>> try( { pdf("./Correlation_1.pdf") IFN.mean <- load.IFN.mean() >>> grid <- load.grid.CASTANEA.average() image(IFN.mean) } ) >>> dev.off() >>> >>> The device would be closed even if an error occurred during the >>> execution of the code. >>> >>> But still, when exporting to pdf, the call to pdflatex fails as >>> only a empty pdf is available. So it becomes necessary to go >>> through the pdf log to identify the graphs which failed. >>> >>> In this case it would be useful, to have a placeholder grah in >>> the final pdf, so that one can see which graphs did not work. >>> >>> In addition, this could be used as placeholders (well - they are >>> placeholders) for to be created graphs, while the text has >>> already been written. >>> >>> So my second suggestion would be to include a placeholder image, >>> which would be used if the generation of the actual graph fails. >>> It would be great (but not necessary) if the actual error >>> message would be in the image. >> >> Such an place holder image would be great, indeed. >> >> >> Thanks for bringing this up! >> >> Regards, Andreas >> >> > > -- > Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation > Biology, UCT), Dipl. Phys. (Germany) > > Centre of Excellence for Invasion Biology > Stellenbosch University > South Africa > > Tel : +33 - (0)9 53 10 27 44 > Cell: +33 - (0)6 85 62 59 98 > Fax : +33 - (0)9 58 10 27 44 > > Fax (D): +49 - (0)3 21 21 25 22 44 > > email: Rainer@krugs.de > > Skype: RMkrug -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [babel] suggestion: wrap creation of graphics into try() block 2014-01-20 15:28 ` Eric Schulte @ 2014-01-20 17:02 ` Rainer M Krug 2014-01-20 18:38 ` Eric Schulte 0 siblings, 1 reply; 11+ messages in thread From: Rainer M Krug @ 2014-01-20 17:02 UTC (permalink / raw) To: Eric Schulte; +Cc: Andreas Leha, emacs-orgmode -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 01/20/14, 16:28 , Eric Schulte wrote: > Rainer M Krug <Rainer@krugs.de> writes: > >> On 01/20/14, 15:00 , Andreas Leha wrote: >>> Rainer M Krug <Rainer@krugs.de> writes: >>> >>>> Hi >>>> >>>> I have two suggestions which are liked to each other. They >>>> are based on R code blocks, but the should be useful for >>>> other languages as well. >>>> >>>> I have a document in which I use :session for creating R >>>> graphs. These look like: >>>> >>>> #+begin_src R :file Correlation_1.pdf :results graphics >>>> IFN.mean <- load.IFN.mean() grid <- >>>> load.grid.CASTANEA.average() image(IFN.mean) #+end_src >>>> >>>> Everything works fine, unless there is an error in one >>>> graph. >>>> >>>> In this case, the device remains open, which leaves open >>>> devices at the end of the export of the document. >>> >>> I experience the same problem. And would love to see that >>> addressed. >> >> Just checked in the code from ob-R.el, and it should not be to >> difficult: >> >> The functions org-babel-R-construct-graphics-device-call and >> org-babel-expand-body:R >> >> would be affected. >> >> I changed : >> >> >> >> ... Trying it out ... >> >> This seems to be working - I just changed it and it closes the >> device. But further tests are needed. I will leave it to see if >> anything unexpected happens. >> > > Sounds great. When you're confident that this is working please > submit a patch and I'll be happy to apply it. I will check it a little bit longer and see that I can display the error message in the dummy graphic. Should have it by tomorrow. I'll send you the patch then. This is the first time I really work with patches - I assume "git diff" will give me the patch you need? Cheers, Rainer > > Thanks, > >> >> If somebody could look if this makes sense? (defun >> org-babel-expand-body:R (body params &optional graphics-file) >> "Expand BODY according to PARAMS, return the expanded body." (let >> ((graphics-file (or graphics-file >> (org-babel-R-graphical-output-file params)))) (mapconcat >> #'identity (let ((inside (append (when (cdr (assoc :prologue >> params)) (list (cdr (assoc :prologue params)))) >> (org-babel-variable-assignments:R params) (list body) (when (cdr >> (assoc :epilogue params)) (list (cdr (assoc :epilogue >> params))))))) (if graphics-file (append (list >> (org-babel-R-construct-graphics-device-call graphics-file >> params)) inside ;; my edits (list "},error=function(e){plot(-1:1, >> -1:1, type='n'); text(0,0,'DUMMY')}); dev.off()")) inside)) ;; >> end "\n"))) >> >> >> >> and >> >> (format "%s(%s=\"%s\"%s%s%s); tryCatch({" device filearg out-file >> args (if extra-args "," "") (or extra-args "")))) >> >> in org-babel-R-construct-graphics-device-call >> >> It is working with the Dummy. >> >> Could somebody please check if this is working? >> >> I am leaving my changes and will see during my work if it is >> fine. >> >> Cheers, >> >> Rainer >> >> >>> >>>> >>>> If the code block which should create the graph would be >>>> wrapped into a try() block, so that it would look like the >>>> following: >>>> >>>> try( { pdf("./Correlation_1.pdf") IFN.mean <- >>>> load.IFN.mean() grid <- load.grid.CASTANEA.average() >>>> image(IFN.mean) } ) dev.off() >>>> >>>> The device would be closed even if an error occurred during >>>> the execution of the code. >>>> >>>> But still, when exporting to pdf, the call to pdflatex fails >>>> as only a empty pdf is available. So it becomes necessary to >>>> go through the pdf log to identify the graphs which failed. >>>> >>>> In this case it would be useful, to have a placeholder grah >>>> in the final pdf, so that one can see which graphs did not >>>> work. >>>> >>>> In addition, this could be used as placeholders (well - they >>>> are placeholders) for to be created graphs, while the text >>>> has already been written. >>>> >>>> So my second suggestion would be to include a placeholder >>>> image, which would be used if the generation of the actual >>>> graph fails. It would be great (but not necessary) if the >>>> actual error message would be in the image. >>> >>> Such an place holder image would be great, indeed. >>> >>> >>> Thanks for bringing this up! >>> >>> Regards, Andreas >>> >>> >> >> -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc >> (Conservation Biology, UCT), Dipl. Phys. (Germany) >> >> Centre of Excellence for Invasion Biology Stellenbosch >> University South Africa >> >> Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 >> 59 98 Fax : +33 - (0)9 58 10 27 44 >> >> Fax (D): +49 - (0)3 21 21 25 22 44 >> >> email: Rainer@krugs.de >> >> Skype: RMkrug > - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 59 98 Fax : +33 - (0)9 58 10 27 44 Fax (D): +49 - (0)3 21 21 25 22 44 email: Rainer@krugs.de Skype: RMkrug -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJS3ValAAoJENvXNx4PUvmClnYIAJiHXrgXaQoZuyvIS8kpW9QR iBJUirAZK+49CQEfwoFulWwr46jEqyAxX5eJEUAe1jw6plNRkS7qvuxYWqmydDII m588aiQ7sB2jo72LF/Lo/qv1niYaWjBRH6gTQ8aN3I4kj2ZLOOSD3dDjkEZsoLjf QpmQaAHnHwcBZ3+OLczbtjgCW/a8VrYK1LlVdZ1mNu4i151PMurdvZyeZ9Mj++aZ wpT/KybjFkBtKTm/bEUtcV3ZfwG9BW3xhXZBTIDtSxq8EzWBg92LrCEYq8jzJElV LU+3A3l6NxuD8WM92CsScNkiutnVGmhrvxFopLD13WbWpMIDuob7kN5lrQql2Uc= =lHhr -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [babel] suggestion: wrap creation of graphics into try() block 2014-01-20 17:02 ` Rainer M Krug @ 2014-01-20 18:38 ` Eric Schulte 2014-01-21 9:52 ` Rainer M Krug 0 siblings, 1 reply; 11+ messages in thread From: Eric Schulte @ 2014-01-20 18:38 UTC (permalink / raw) To: Rainer; +Cc: Andreas Leha, emacs-orgmode > > I will check it a little bit longer and see that I can display the > error message in the dummy graphic. Should have it by tomorrow. > Sounds good. Alternately, maybe you could get the R process to fail and print an error to STDERR so that the export will stop immediately and inform the user of the error. > > I'll send you the patch then. > Sounds great, thanks. > > This is the first time I really work with patches - I assume "git > diff" will give me the patch you need? > The best would be to create the patch with git format-patch, see http://orgmode.org/worg/org-contribute.html#sec-4-2. If the patch changes more than 10 lines, you'll need to fill out the FSF copyright assignment paperwork. Thanks, > > Cheers, > > Rainer > >> >> Thanks, >> >>> >>> If somebody could look if this makes sense? (defun >>> org-babel-expand-body:R (body params &optional graphics-file) >>> "Expand BODY according to PARAMS, return the expanded body." (let >>> ((graphics-file (or graphics-file >>> (org-babel-R-graphical-output-file params)))) (mapconcat >>> #'identity (let ((inside (append (when (cdr (assoc :prologue >>> params)) (list (cdr (assoc :prologue params)))) >>> (org-babel-variable-assignments:R params) (list body) (when (cdr >>> (assoc :epilogue params)) (list (cdr (assoc :epilogue >>> params))))))) (if graphics-file (append (list >>> (org-babel-R-construct-graphics-device-call graphics-file >>> params)) inside ;; my edits (list "},error=function(e){plot(-1:1, >>> -1:1, type='n'); text(0,0,'DUMMY')}); dev.off()")) inside)) ;; >>> end "\n"))) >>> >>> >>> >>> and >>> >>> (format "%s(%s=\"%s\"%s%s%s); tryCatch({" device filearg out-file >>> args (if extra-args "," "") (or extra-args "")))) >>> >>> in org-babel-R-construct-graphics-device-call >>> >>> It is working with the Dummy. >>> >>> Could somebody please check if this is working? >>> >>> I am leaving my changes and will see during my work if it is >>> fine. >>> >>> Cheers, >>> >>> Rainer >>> >>> >>>> >>>>> >>>>> If the code block which should create the graph would be >>>>> wrapped into a try() block, so that it would look like the >>>>> following: >>>>> >>>>> try( { pdf("./Correlation_1.pdf") IFN.mean <- >>>>> load.IFN.mean() grid <- load.grid.CASTANEA.average() >>>>> image(IFN.mean) } ) dev.off() >>>>> >>>>> The device would be closed even if an error occurred during >>>>> the execution of the code. >>>>> >>>>> But still, when exporting to pdf, the call to pdflatex fails >>>>> as only a empty pdf is available. So it becomes necessary to >>>>> go through the pdf log to identify the graphs which failed. >>>>> >>>>> In this case it would be useful, to have a placeholder grah >>>>> in the final pdf, so that one can see which graphs did not >>>>> work. >>>>> >>>>> In addition, this could be used as placeholders (well - they >>>>> are placeholders) for to be created graphs, while the text >>>>> has already been written. >>>>> >>>>> So my second suggestion would be to include a placeholder >>>>> image, which would be used if the generation of the actual >>>>> graph fails. It would be great (but not necessary) if the >>>>> actual error message would be in the image. >>>> >>>> Such an place holder image would be great, indeed. >>>> >>>> >>>> Thanks for bringing this up! >>>> >>>> Regards, Andreas >>>> >>>> >>> >>> -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc >>> (Conservation Biology, UCT), Dipl. Phys. (Germany) >>> >>> Centre of Excellence for Invasion Biology Stellenbosch >>> University South Africa >>> >>> Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 >>> 59 98 Fax : +33 - (0)9 58 10 27 44 >>> >>> Fax (D): +49 - (0)3 21 21 25 22 44 >>> >>> email: Rainer@krugs.de >>> >>> Skype: RMkrug >> > > -- > Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation > Biology, UCT), Dipl. Phys. (Germany) > > Centre of Excellence for Invasion Biology > Stellenbosch University > South Africa > > Tel : +33 - (0)9 53 10 27 44 > Cell: +33 - (0)6 85 62 59 98 > Fax : +33 - (0)9 58 10 27 44 > > Fax (D): +49 - (0)3 21 21 25 22 44 > > email: Rainer@krugs.de > > Skype: RMkrug -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [babel] suggestion: wrap creation of graphics into try() block 2014-01-20 18:38 ` Eric Schulte @ 2014-01-21 9:52 ` Rainer M Krug 2014-01-21 10:03 ` Andreas Leha 2014-01-26 18:07 ` Eric Schulte 0 siblings, 2 replies; 11+ messages in thread From: Rainer M Krug @ 2014-01-21 9:52 UTC (permalink / raw) To: Eric Schulte; +Cc: Andreas Leha, emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 6453 bytes --] -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 01/20/14, 19:38 , Eric Schulte wrote: >> >> I will check it a little bit longer and see that I can display >> the error message in the dummy graphic. Should have it by >> tomorrow. >> > > Sounds good. Alternately, maybe you could get the R process to > fail and print an error to STDERR so that the export will stop > immediately and inform the user of the error. I think it is better to catch the error and return with the computations in the next block, because 1) a code block which produces a graph is most often an end point, i.e. further blocks should (as I see it) not rely on the output of this block 2) if the export continues, one can fix more then one error at a time, so being more efficient. 3) If the export continues, it makes it possible to use this to create placeholder graphs: #+begin_src R :file TheFantasticGraph.pdf :results graphics stop("This is a placeholder for a new fantastic graph" #+end_src Where TheFantasticGraph will display the message "This is a placeholder for a new fantastic graph". I have now added the error to the normal R output in addition to a graph, but the export is not canceled. > >> >> I'll send you the patch then. >> > > Sounds great, thanks. OK - here it is attached (my first patch to org :-) ) - let me know if it is OK. > >> >> This is the first time I really work with patches - I assume >> "git diff" will give me the patch you need? >> > > The best would be to create the patch with git format-patch, see > http://orgmode.org/worg/org-contribute.html#sec-4-2. > > If the patch changes more than 10 lines, you'll need to fill out > the FSF copyright assignment paperwork. It is two lines, but it might be worth considering to d=o the paperwork, as I am thinking about doing some other things on ob-R.el > > Thanks, My pleasure, Rainer > >> >> Cheers, >> >> Rainer >> >>> >>> Thanks, >>> >>>> >>>> If somebody could look if this makes sense? (defun >>>> org-babel-expand-body:R (body params &optional >>>> graphics-file) "Expand BODY according to PARAMS, return the >>>> expanded body." (let ((graphics-file (or graphics-file >>>> (org-babel-R-graphical-output-file params)))) (mapconcat >>>> #'identity (let ((inside (append (when (cdr (assoc :prologue >>>> params)) (list (cdr (assoc :prologue params)))) >>>> (org-babel-variable-assignments:R params) (list body) (when >>>> (cdr (assoc :epilogue params)) (list (cdr (assoc :epilogue >>>> params))))))) (if graphics-file (append (list >>>> (org-babel-R-construct-graphics-device-call graphics-file >>>> params)) inside ;; my edits (list >>>> "},error=function(e){plot(-1:1, -1:1, type='n'); >>>> text(0,0,'DUMMY')}); dev.off()")) inside)) ;; end "\n"))) >>>> >>>> >>>> >>>> and >>>> >>>> (format "%s(%s=\"%s\"%s%s%s); tryCatch({" device filearg >>>> out-file args (if extra-args "," "") (or extra-args "")))) >>>> >>>> in org-babel-R-construct-graphics-device-call >>>> >>>> It is working with the Dummy. >>>> >>>> Could somebody please check if this is working? >>>> >>>> I am leaving my changes and will see during my work if it is >>>> fine. >>>> >>>> Cheers, >>>> >>>> Rainer >>>> >>>> >>>>> >>>>>> >>>>>> If the code block which should create the graph would be >>>>>> wrapped into a try() block, so that it would look like >>>>>> the following: >>>>>> >>>>>> try( { pdf("./Correlation_1.pdf") IFN.mean <- >>>>>> load.IFN.mean() grid <- load.grid.CASTANEA.average() >>>>>> image(IFN.mean) } ) dev.off() >>>>>> >>>>>> The device would be closed even if an error occurred >>>>>> during the execution of the code. >>>>>> >>>>>> But still, when exporting to pdf, the call to pdflatex >>>>>> fails as only a empty pdf is available. So it becomes >>>>>> necessary to go through the pdf log to identify the >>>>>> graphs which failed. >>>>>> >>>>>> In this case it would be useful, to have a placeholder >>>>>> grah in the final pdf, so that one can see which graphs >>>>>> did not work. >>>>>> >>>>>> In addition, this could be used as placeholders (well - >>>>>> they are placeholders) for to be created graphs, while >>>>>> the text has already been written. >>>>>> >>>>>> So my second suggestion would be to include a >>>>>> placeholder image, which would be used if the generation >>>>>> of the actual graph fails. It would be great (but not >>>>>> necessary) if the actual error message would be in the >>>>>> image. >>>>> >>>>> Such an place holder image would be great, indeed. >>>>> >>>>> >>>>> Thanks for bringing this up! >>>>> >>>>> Regards, Andreas >>>>> >>>>> >>>> >>>> -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc >>>> (Conservation Biology, UCT), Dipl. Phys. (Germany) >>>> >>>> Centre of Excellence for Invasion Biology Stellenbosch >>>> University South Africa >>>> >>>> Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 >>>> 62 59 98 Fax : +33 - (0)9 58 10 27 44 >>>> >>>> Fax (D): +49 - (0)3 21 21 25 22 44 >>>> >>>> email: Rainer@krugs.de >>>> >>>> Skype: RMkrug >>> >> >> -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc >> (Conservation Biology, UCT), Dipl. Phys. (Germany) >> >> Centre of Excellence for Invasion Biology Stellenbosch >> University South Africa >> >> Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 >> 59 98 Fax : +33 - (0)9 58 10 27 44 >> >> Fax (D): +49 - (0)3 21 21 25 22 44 >> >> email: Rainer@krugs.de >> >> Skype: RMkrug > - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 59 98 Fax : +33 - (0)9 58 10 27 44 Fax (D): +49 - (0)3 21 21 25 22 44 email: Rainer@krugs.de Skype: RMkrug -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJS3kNyAAoJENvXNx4PUvmCZXkIAMLm2LTuB8/FFZidI12yRhuF N90DVeqYYcHpsJYTIk74W3EX2Wj6p4zjH84TXsVRUc3CRnh2EploU7MTYbdxtshC VLTLsKxgfX8FKXz78ADeUqFmOL6KkJihS+P09mrkqwzq652YvGKbw3H0NLwQDfnR Dp4K3wwYfArFtteCPNgZjBcUVgKF5guyfpEvdYEroR7bJ2wHp4FCaQuaKGXxIPfk oXDDwiIjM7+cboZ4Nub6JnSu48GjTKbP0IkP81ejGpgl4JdE447Z13ikvRAeWfL1 dbWbL0aQSmdpeg/3M21Os9XtOcSesD21ueHUW5sblfAIAjIZRDpW++2jfCA6hS0= =Hro3 -----END PGP SIGNATURE----- [-- Attachment #2: 0001-Graphic-Catch-errors-and-return-error-message.patch --] [-- Type: text/plain, Size: 1716 bytes --] From 3805d053a912ede4ae377b22f10c3562ebd4b967 Mon Sep 17 00:00:00 2001 From: "Rainer M. Krug" <R.M.Krug@gmail.com> Date: Tue, 21 Jan 2014 10:35:52 +0100 Subject: [PATCH] Graphic: Catch errors and return error message * lisp/ob-R.el (org-babel-expand-body:R): Added the opening of the tryCatch() wrapper * lisp/ob-R.el (org-babel-R-construct-graphics-device-call): Added closing of the wrapper containing the error function. Added tryCatch() wrapper around the execution of the source block so that if an error occurs - the R graphic device is closed even when an error occurs - a graph containing the error message is created - the error message is printed in the R session in the form ERROR : the error message TINYCHANGE --- lisp/ob-R.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index c907d18..62aa7f2 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -112,7 +112,7 @@ this variable.") (list (org-babel-R-construct-graphics-device-call graphics-file params)) inside - (list "dev.off()")) + (list "},error=function(e){plot(x=-1:1, y=-1:1, type='n', xlab='', ylab='', axes=FALSE); text(x=0, y=0, labels=e$message, col='red'); paste('ERROR', e$message, sep=' : ')}); dev.off()")) inside)) "\n"))) @@ -295,7 +295,7 @@ Each member of this list is a list with three members: (substring (symbol-name (car pair)) 1) (cdr pair)) "")) params "")) - (format "%s(%s=\"%s\"%s%s%s)" + (format "%s(%s=\"%s\"%s%s%s); tryCatch({" device filearg out-file args (if extra-args "," "") (or extra-args "")))) -- 1.8.3.4 (Apple Git-47) ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [babel] suggestion: wrap creation of graphics into try() block 2014-01-21 9:52 ` Rainer M Krug @ 2014-01-21 10:03 ` Andreas Leha 2014-01-21 10:43 ` :draft header argument for source block evaluation - WAS: " Rainer M Krug 2014-01-26 18:07 ` Eric Schulte 1 sibling, 1 reply; 11+ messages in thread From: Andreas Leha @ 2014-01-21 10:03 UTC (permalink / raw) To: emacs-orgmode Hi Rainer, really cool. I am very short on time right now, so I can't promise I'll get around to test it soon. Just one comment: Rainer M Krug <Rainer@krugs.de> writes: > On 01/20/14, 19:38 , Eric Schulte wrote: >>> >>> I will check it a little bit longer and see that I can display >>> the error message in the dummy graphic. Should have it by >>> tomorrow. >>> >> >> Sounds good. Alternately, maybe you could get the R process to >> fail and print an error to STDERR so that the export will stop >> immediately and inform the user of the error. > > I think it is better to catch the error and return with the > computations in the next block, because > > 1) a code block which produces a graph is most often an end point, > i.e. further blocks should (as I see it) not rely on the output of > this block If all (your) documents follow that rule, that blocks producing graphical output are not needed later on, than it might be cool to have an [draft]-like option in Org that by default replaces all images (not just failing ones) with a cheap-to-export graphic. For some of my documents that is a real time saver. I can mimic that now by passing a variable 'draft' to the code blocks and deal with it internally. But that means a lot of manual coding. > > 2) if the export continues, one can fix more then one error at a time, > so being more efficient. > > 3) If the export continues, it makes it possible to use this to create > placeholder graphs: > > #+begin_src R :file TheFantasticGraph.pdf :results graphics > stop("This is a placeholder for a new fantastic graph" > #+end_src > > Where TheFantasticGraph will display the message "This is a > placeholder for a new fantastic graph". > > I have now added the error to the normal R output in addition to a > graph, but the export is not canceled. > > >> >>> >>> I'll send you the patch then. >>> >> >> Sounds great, thanks. > > OK - here it is attached (my first patch to org :-) ) - let me know if > it is OK. > Really nice addition! Thanks already (without testing the patch)! [ ... ] Regards, Andreas ^ permalink raw reply [flat|nested] 11+ messages in thread
* :draft header argument for source block evaluation - WAS: [babel] suggestion: wrap creation of graphics into try() block 2014-01-21 10:03 ` Andreas Leha @ 2014-01-21 10:43 ` Rainer M Krug 0 siblings, 0 replies; 11+ messages in thread From: Rainer M Krug @ 2014-01-21 10:43 UTC (permalink / raw) To: Andreas Leha, emacs-orgmode, Eric Schulte, Eric Fraga -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 01/21/14, 11:03 , Andreas Leha wrote: > Hi Rainer, > > really cool. I am very short on time right now, so I can't promise > I'll get around to test it soon. Great. > > Just one comment: > > Rainer M Krug <Rainer@krugs.de> writes: > >> On 01/20/14, 19:38 , Eric Schulte wrote: >>>> >>>> I will check it a little bit longer and see that I can >>>> display the error message in the dummy graphic. Should have >>>> it by tomorrow. >>>> >>> >>> Sounds good. Alternately, maybe you could get the R process >>> to fail and print an error to STDERR so that the export will >>> stop immediately and inform the user of the error. >> >> I think it is better to catch the error and return with the >> computations in the next block, because >> >> 1) a code block which produces a graph is most often an end >> point, i.e. further blocks should (as I see it) not rely on the >> output of this block > > If all (your) documents follow that rule, that blocks producing > graphical output are not needed later on, than it might be cool to > have an [draft]-like option in Org that by default replaces all > images (not just failing ones) with a cheap-to-export graphic. For > some of my documents that is a real time saver. I thought about that as well. a header argument :draft would be very useful for *many* aspects. Effectively, one could use the initially the following approach: - - :draft null (default) :: everything as usual - - :draft graphics :: Does not evaluate :results graphic blocks and instead of the graphic, displays a "graphic" with "DRAFT - the code block name if any", everything else as usual - - :draft all :: does not evaluate *any* code block but instead returns a message (if anything should be returned) with "DRAFT - the code block name if any" Something like this would be very useful, not only for R. It could be useful to have this, as a per language header argument, but one could start with R? > > I can mimic that now by passing a variable 'draft' to the code > blocks and deal with it internally. But that means a lot of manual > coding. > >> >> 2) if the export continues, one can fix more then one error at a >> time, so being more efficient. >> >> 3) If the export continues, it makes it possible to use this to >> create placeholder graphs: >> >> #+begin_src R :file TheFantasticGraph.pdf :results graphics >> stop("This is a placeholder for a new fantastic graph" #+end_src >> >> Where TheFantasticGraph will display the message "This is a >> placeholder for a new fantastic graph". >> >> I have now added the error to the normal R output in addition to >> a graph, but the export is not canceled. >> >> >>> >>>> >>>> I'll send you the patch then. >>>> >>> >>> Sounds great, thanks. >> >> OK - here it is attached (my first patch to org :-) ) - let me >> know if it is OK. >> > > Really nice addition! Thanks already (without testing the patch)! Thanks, and I hope it works as well on your side... Cheers, Rainer > > [ ... ] > > Regards, Andreas > > - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 59 98 Fax : +33 - (0)9 58 10 27 44 Fax (D): +49 - (0)3 21 21 25 22 44 email: Rainer@krugs.de Skype: RMkrug -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJS3k9AAAoJENvXNx4PUvmCnXEIANECzlTYZFBXOAVMGsl890jN B4R5Ytq8Br09LDrB1HcnrZ59/rSRjLTBb8y2n+dn7uunsG3TlwK8GtqNYN2AXGDf RUpwFrmbF4NxR6qCMQ/LiNp7ogEIyQgADEfLu9qvHB0yXcm7ylo3yqzDOirhMo1A R3S57jUpPskfyEMcmVtco2k9SFYQ6qf5+IGQuVoOPKiN4L7HtTTNjW1YwQQmmIG9 W7krKxpFdqjlJYr9KzdMx8N8pskGKSvJTtJLFWElGAEvjopJvPQEeG8zLeaffL1M EXarECSAbuS8ymjitBCuETDi0ShlYYOOiVCg/GJIGCwCS673cqky3QJkR/DO6dQ= =JZYc -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [babel] suggestion: wrap creation of graphics into try() block 2014-01-21 9:52 ` Rainer M Krug 2014-01-21 10:03 ` Andreas Leha @ 2014-01-26 18:07 ` Eric Schulte 2014-01-27 9:10 ` Rainer M Krug 1 sibling, 1 reply; 11+ messages in thread From: Eric Schulte @ 2014-01-26 18:07 UTC (permalink / raw) To: Rainer; +Cc: Andreas Leha, emacs-orgmode >>> >>> I'll send you the patch then. >>> >> >> Sounds great, thanks. > > OK - here it is attached (my first patch to org :-) ) - let me know if > it is OK. > Looks good to me, I've just applied it. Thanks! -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [babel] suggestion: wrap creation of graphics into try() block 2014-01-26 18:07 ` Eric Schulte @ 2014-01-27 9:10 ` Rainer M Krug 0 siblings, 0 replies; 11+ messages in thread From: Rainer M Krug @ 2014-01-27 9:10 UTC (permalink / raw) To: Eric Schulte; +Cc: Andreas Leha, emacs-orgmode -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Thanks a lot, Rainer On 01/26/14, 19:07 , Eric Schulte wrote: >>>> >>>> I'll send you the patch then. >>>> >>> >>> Sounds great, thanks. >> >> OK - here it is attached (my first patch to org :-) ) - let me >> know if it is OK. >> > > Looks good to me, I've just applied it. > > Thanks! > > - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 59 98 Fax : +33 - (0)9 58 10 27 44 Fax (D): +49 - (0)3 21 21 25 22 44 email: Rainer@krugs.de Skype: RMkrug -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJS5iKRAAoJENvXNx4PUvmCqfMIAPHLOvhQLI355MJ5SRvF59KE 4zlNPAABeLXiOHtP+y0j09j0n+a2tChwooB0BFkjZS9hLgvcNSLTSXMruiHJ/xAb 1WBVWK0hU1GyZP5f+bWu14HwNHR520XDS0ExB62+q+Z/YpOev9rpvIQtVQnQwHKd M2EDiO1MFIJZbtYdFK711nq0QGoXnz2QriWHyNwFJJcyOrZqxRSAv72COtHAecoO H4R/norClwreMzFyK0lnX1fWLmBgEvtT2s5hgy5TIwz4GDDUAmu4oFDuTxBhbHPl VGxEj+wI5WjnqUroCxeyL9710sGYDfqqctaLgAUGiVDvYGsVh2UDwZUdSanso1A= =6hRr -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2014-01-27 9:10 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-01-20 13:36 [babel] suggestion: wrap creation of graphics into try() block Rainer M Krug 2014-01-20 14:00 ` Andreas Leha 2014-01-20 15:13 ` Rainer M Krug 2014-01-20 15:28 ` Eric Schulte 2014-01-20 17:02 ` Rainer M Krug 2014-01-20 18:38 ` Eric Schulte 2014-01-21 9:52 ` Rainer M Krug 2014-01-21 10:03 ` Andreas Leha 2014-01-21 10:43 ` :draft header argument for source block evaluation - WAS: " Rainer M Krug 2014-01-26 18:07 ` Eric Schulte 2014-01-27 9:10 ` Rainer M Krug
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.