[Rd] strange value in .Last.value

Duncan Murdoch murdoch.duncan at gmail.com
Wed Jun 5 16:28:29 CEST 2013


On 05/06/2013 10:18 AM, Vitalie Spinu wrote:
>
>   >> Duncan Murdoch <murdoch.duncan at gmail.com>
>   >> on Wed, 5 Jun 2013 07:59:54 -0400 wrote:
>
> [...]
>
>   >> As I take it, it is.  Thus, ess/orgmode -- which relies on .Last.value
>   >> for results handling and does not expect that $visible element -- should
>   >> adapt and ignore that explicitly?
>
>   > I think you'll need to ask on the ESS list what the intentions are in this case.
>   > The result of source() is a list with the value and visible entries.  This has
>   > been true "forever", it's not new behaviour.  (It's unfortunate that this is not
>   > clearly documented.)
>
> ESS recently switched to "source" for evaluation in order to preserve
> source references, and that ruins org-babel (a literate programming
> backend) that relies on .Last.value.
>
> Would a
>
>       invisible(source('file.R', echo=TRUE)$value)
>
> be a reliable solution to the problem?

You can count on source()$value to return the last value computed in the 
source() if there was one.  If there were no expressions computed, the 
value will be NULL, but NULL$value is also NULL, so perhaps that is good 
enough for your purposes.

Duncan Murdoch



More information about the R-devel mailing list