Re: $$e not set on import --> import of .Rnw (knitr) fails

2012-10-20 Thread Scott Kostyshak
On Sat, Oct 20, 2012 at 6:17 PM, Yihui Xie  wrote:
> I think it should be easy to ignore the encoding argument if it does
> not exist, but the problem that confuses me is why importing Rnw is
> involved with lyxsweave.R or lyxknitr.R. I mean Rnw should be treated
> as a normal TeX document (the R code should not be executed through
> Sweave or knitr), except that the code chunks (between <<>>= and @)
> should be treated differently, e.g. as ERT.

You're right. Now I understand what JMarc was saying -- this converter
should not be used for importing. This is the problem.

Scott


Re: $$e not set on import --> import of .Rnw (knitr) fails

2012-10-20 Thread Yihui Xie
I think it should be easy to ignore the encoding argument if it does
not exist, but the problem that confuses me is why importing Rnw is
involved with lyxsweave.R or lyxknitr.R. I mean Rnw should be treated
as a normal TeX document (the R code should not be executed through
Sweave or knitr), except that the code chunks (between <<>>= and @)
should be treated differently, e.g. as ERT.

Regards,
Yihui
--
Yihui Xie 
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA


On Sat, Oct 20, 2012 at 11:13 AM, Scott Kostyshak  wrote:
> On Fri, Oct 19, 2012 at 5:11 AM, Jean-Marc Lasgouttes
>  wrote:
>> Le 18/10/2012 16:19, Scott Kostyshak a écrit :
>>
>>> The unchangedConverter.log is here (error):
>>> http://paste.debian.net/201557/
>>
>>
>> So the error happens on export to latex because the encoding is not
>> specified.
>
> The error happens when importing the Rnw in LyX, which from what I
> understand currently calls the Rnw -> LaTeX (plain) converter and then
> run tex2lyx.
>
>> I think I do not understand what you do exactly. Does the same happen with
>> Sweave (I do not have knitr here)?
>
> Yes, the same happens with Sweave because the converter Sweave ->
> LaTeX (plain) has a $$e and that string is set to empty because of the
> following code:
> command = subst(command, token_encoding, buffer ?
> buffer->params().encoding().iconvName() : string());
>
>> Could you send me an example file and a
>> step by step description of what you actually do?
>
> Yes. I've been using the example file that comes with LyX but I think
> that the same error would occur with trying to import any .Rnw file
> via Sweave or knitr.
>
> 1. Start a clean LyX instance from current master branch (although I
> have the same problem in branch. I wonder if importing a .Rnw has
> worked at some point?).
> 2. File > Open > Examples button > sweave.lyx
> 3. File > Export > Export As > [tempfolder]/sweaveexample.Rnw  (select
> the Sweave (.Rnw) format)
> 4. Close the current document (the sweave.lyx file) just to make sure
> that it's not involved with the import probem.
> 5. File > Import > Sweave... > [tempfolder]/sweaveexample.Rnw
> 6. At this point I get an error.
>
> Here are steps to show that (1) it is indeed the Sweave -> LaTeX
> (plain) converter that is being used and (2) that setting the $$e
> variable improves things:
> 7. Close the error box from (6).
> 8. Go to Tools > Preferences > File Handling > Converters > select
> Sweave -> LaTeX (plain) and in the Converter text box manually delete
> "$$e" and insert in it's place "ISO-8859-15" so that the converter is
> now:
> Rscript --verbose --no-save --no-restore $$s/scripts/lyxsweave.R
> $$p$$i $$p$$o ISO-8859-15 $$r
> 9. Click the Modify button.
> 10. Click the Save button.
> 11. Repeat step (5).
> 12. The .Rnw is now partly imported. There will be other problems in
> the import process which I think are due to tex2lyx, but these
> problems are different from the Rnw -> tex problem I am reporting
> here.
>
> Is the solution to modify lyxsweave.R and lyxknitr.R so that if they
> are not passed an encoding they should just not change the encoding
> from the default R one? This would be easy to do.
>
> Thanks,
>
> Scott


Re: $$e not set on import --> import of .Rnw (knitr) fails

2012-10-20 Thread Scott Kostyshak
On Fri, Oct 19, 2012 at 5:11 AM, Jean-Marc Lasgouttes
 wrote:
> Le 18/10/2012 16:19, Scott Kostyshak a écrit :
>
>> The unchangedConverter.log is here (error):
>> http://paste.debian.net/201557/
>
>
> So the error happens on export to latex because the encoding is not
> specified.

The error happens when importing the Rnw in LyX, which from what I
understand currently calls the Rnw -> LaTeX (plain) converter and then
run tex2lyx.

> I think I do not understand what you do exactly. Does the same happen with
> Sweave (I do not have knitr here)?

Yes, the same happens with Sweave because the converter Sweave ->
LaTeX (plain) has a $$e and that string is set to empty because of the
following code:
command = subst(command, token_encoding, buffer ?
buffer->params().encoding().iconvName() : string());

> Could you send me an example file and a
> step by step description of what you actually do?

Yes. I've been using the example file that comes with LyX but I think
that the same error would occur with trying to import any .Rnw file
via Sweave or knitr.

1. Start a clean LyX instance from current master branch (although I
have the same problem in branch. I wonder if importing a .Rnw has
worked at some point?).
2. File > Open > Examples button > sweave.lyx
3. File > Export > Export As > [tempfolder]/sweaveexample.Rnw  (select
the Sweave (.Rnw) format)
4. Close the current document (the sweave.lyx file) just to make sure
that it's not involved with the import probem.
5. File > Import > Sweave... > [tempfolder]/sweaveexample.Rnw
6. At this point I get an error.

Here are steps to show that (1) it is indeed the Sweave -> LaTeX
(plain) converter that is being used and (2) that setting the $$e
variable improves things:
7. Close the error box from (6).
8. Go to Tools > Preferences > File Handling > Converters > select
Sweave -> LaTeX (plain) and in the Converter text box manually delete
"$$e" and insert in it's place "ISO-8859-15" so that the converter is
now:
Rscript --verbose --no-save --no-restore $$s/scripts/lyxsweave.R
$$p$$i $$p$$o ISO-8859-15 $$r
9. Click the Modify button.
10. Click the Save button.
11. Repeat step (5).
12. The .Rnw is now partly imported. There will be other problems in
the import process which I think are due to tex2lyx, but these
problems are different from the Rnw -> tex problem I am reporting
here.

Is the solution to modify lyxsweave.R and lyxknitr.R so that if they
are not passed an encoding they should just not change the encoding
from the default R one? This would be easy to do.

Thanks,

Scott


Re: $$e not set on import --> import of .Rnw (knitr) fails

2012-10-19 Thread Kayvan Sylvan
I can put some time into this next week.

Yes, I noticed (and very much appreciate) that you don't need to use
CTRL-return anymore.

Best regards,

Kayvan

On Oct 19, 2012, at 2:00, Jean-Marc Lasgouttes  wrote:

> Le 18/10/2012 15:57, Kayvan Sylvan a écrit :
>> The [[foo]] notation is noweb syntax for a reference to something that
>> is defined elsewhere. By putting it in an ERT we ensure that it ends
>> up in the noweb file unaltered.
>
> I was wondering whether this could clash with Sweave documents, which do
> not use such syntax AFAIK.
>
> BTW, Kayvan, it would be nice to update the Noweb For LyX  documentation
> to explain how to use the noweb module instead of the specific
> literate-* classes. Actually, I would like to get rid of these classes ASAP.
>
> Note also that it is not necessary anymore to use Ctrl-Return at the end
> of scrap lines.
>
> JMarc


Re: $$e not set on import --> import of .Rnw (knitr) fails

2012-10-19 Thread Jean-Marc Lasgouttes

Le 18/10/2012 16:19, Scott Kostyshak a écrit :

The unchangedConverter.log is here (error):
http://paste.debian.net/201557/


So the error happens on export to latex because the encoding is not 
specified.


I think I do not understand what you do exactly. Does the same happen 
with Sweave (I do not have knitr here)? Could you send me an example 
file and a step by step description of what you actually do?


JMarc



Re: $$e not set on import --> import of .Rnw (knitr) fails

2012-10-19 Thread Jean-Marc Lasgouttes

Le 18/10/2012 15:57, Kayvan Sylvan a écrit :

The [[foo]] notation is noweb syntax for a reference to something that
is defined elsewhere. By putting it in an ERT we ensure that it ends
up in the noweb file unaltered.


I was wondering whether this could clash with Sweave documents, which do 
not use such syntax AFAIK.


BTW, Kayvan, it would be nice to update the Noweb For LyX  documentation 
to explain how to use the noweb module instead of the specific 
literate-* classes. Actually, I would like to get rid of these classes ASAP.


Note also that it is not necessary anymore to use Ctrl-Return at the end 
of scrap lines.


JMarc


Re: $$e not set on import --> import of .Rnw (knitr) fails

2012-10-19 Thread Jean-Marc Lasgouttes

Le 18/10/2012 19:11, Yihui Xie a écrit :

Import Rnw is something I was asked long time ago but have not figured
out how it works. It seems the Sweave/knitr module is called but
really should not be, because these modules are only responsible for
Rnw-->TeX, not for Rnw-->LyX. Or should they? Ideally LyX should be
able to handle the TeX part, and for the R code chunks (<<>>= and @),
they can be imported to ERT, but I do not know how to do that.


Assuming we can fix tex2lyx for our different uses, it would be easier 
if knitr used a file extension different from Sweave's Rnw. This way we 
could define a different knitr>lyx import filter.


JMarc



Re: $$e not set on import --> import of .Rnw (knitr) fails

2012-10-18 Thread Yihui Xie
Import Rnw is something I was asked long time ago but have not figured
out how it works. It seems the Sweave/knitr module is called but
really should not be, because these modules are only responsible for
Rnw-->TeX, not for Rnw-->LyX. Or should they? Ideally LyX should be
able to handle the TeX part, and for the R code chunks (<<>>= and @),
they can be imported to ERT, but I do not know how to do that.

Regards,
Yihui
--
Yihui Xie 
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA


On Thu, Oct 18, 2012 at 5:02 AM, Scott Kostyshak  wrote:
> On Thu, Oct 18, 2012 at 3:46 AM, Jean-Marc Lasgouttes
>  wrote:
>> Le 18/10/12 01:49, Scott Kostyshak a écrit :
>>
 Stupid question; where is importation of knitr files defined in
 converters?
>>>
>>>
>>> Rnw (knitr) -> latex (plain)
>>> The converter is currently:
>>> Rscript --verbose --no-save --no-restore $$s/scripts/lyxknitr.R $$p$$i
>>> $$p$$o $$e $$r
>>> When I change this to the following, import works:
>>> Rscript --verbose --no-save --no-restore $$s/scripts/lyxknitr.R $$p$$i
>>> $$p$$o ISO-8859-15 $$r
>>
>>
>> But this is a converter for export, not import.
>
> Ah, then I don't understand how LyX handles imports. The Customization
> manual does not talk about importing. Doesn't LyX use the converters
> to convert the file to LaTeX and then use tex2lyx to import the tex
> file?
>
>> What is the difference between the Rnw files when you do this change?
>
> No difference. In the recipe for reproducing, steps (1) and (2) are
> the same. To get it to import I only substitute for $$e before step
> (3) (importing).
>
> Scott


Re: $$e not set on import --> import of .Rnw (knitr) fails

2012-10-18 Thread Scott Kostyshak
On Thu, Oct 18, 2012 at 9:11 AM, Jean-Marc Lasgouttes
 wrote:
> Le 18/10/2012 14:55, Scott Kostyshak a écrit :
>
>>> The old way this "noweb mode" works is
>>> 1/ ensure that the class name is literate-something (now it would be
>>> ensure
>>> that some module is loaded and the module name should be passed to
>>> tex2lyx)
>>>
>>> 2/ when a layout starts with <<, change it to a layout with name "Scrap".
>>> This could be OK because the Sweave/knitr modules declare Scrap as a
>>> synonym
>>> for Chunk.
>>>
>>> 3/ transform [[something]] to ERT. I do not know what this is good for,
>>> presumably a noweb-only thing.
>>
>>
>> OK, thanks for the explanation.
>
>
> So my point is that we should fix 1/ and get rid of the literate-xx classes
> if they are still there.

Ah, now I see why importing these types of files is different --
because they depend on modules. I didn't think about that.

>
>
>> Yes, the only thing that changes is what I have as the Converter for
>> Rnw (knitr) to LaTeX (plain). Is there some other output that I can
>> send? Any -dbg flag that I can set to give more information on this?
>
>
> Try "-dbg files".

The unchangedConverter.log is here (error):
http://paste.debian.net/201557/

And the changedConverter.log is here (no error):
http://paste.debian.net/201558/

Thanks,

Scott


Re: $$e not set on import --> import of .Rnw (knitr) fails

2012-10-18 Thread Kayvan Sylvan
The [[foo]] notation is noweb syntax for a reference to something that
is defined elsewhere. By putting it in an ERT we ensure that it ends
up in the noweb file unaltered.

On Oct 18, 2012, at 5:18, Jean-Marc Lasgouttes  wrote:

> Le 18/10/2012 14:02, Scott Kostyshak a écrit :
>> Ah, then I don't understand how LyX handles imports. The Customization
>> manual does not talk about importing. Doesn't LyX use the converters
>> to convert the file to LaTeX and then use tex2lyx to import the tex
>> file?
>
> Normally, the importation is done by tex2lyx using the -n flag, but I
> think that this support needs to be updated to the new world of module
> based literate programming.
>
> The old way this "noweb mode" works is
> 1/ ensure that the class name is literate-something (now it would be
> ensure that some module is loaded and the module name should be passed
> to tex2lyx)
>
> 2/ when a layout starts with <<, change it to a layout with name
> "Scrap". This could be OK because the Sweave/knitr modules declare Scrap
> as a synonym for Chunk.
>
> 3/ transform [[something]] to ERT. I do not know what this is good for,
> presumably a noweb-only thing.
>>
>>> What is the difference between the Rnw files when you do this change?
>>
>> No difference. In the recipe for reproducing, steps (1) and (2) are
>> the same.
>
> You mean that the Rnw files are the same in the two cases? This is weird.
>
> JMarc
>


Re: $$e not set on import --> import of .Rnw (knitr) fails

2012-10-18 Thread Jean-Marc Lasgouttes

Le 18/10/2012 14:55, Scott Kostyshak a écrit :

The old way this "noweb mode" works is
1/ ensure that the class name is literate-something (now it would be ensure
that some module is loaded and the module name should be passed to tex2lyx)

2/ when a layout starts with <<, change it to a layout with name "Scrap".
This could be OK because the Sweave/knitr modules declare Scrap as a synonym
for Chunk.

3/ transform [[something]] to ERT. I do not know what this is good for,
presumably a noweb-only thing.


OK, thanks for the explanation.


So my point is that we should fix 1/ and get rid of the literate-xx 
classes if they are still there.



Yes, the only thing that changes is what I have as the Converter for
Rnw (knitr) to LaTeX (plain). Is there some other output that I can
send? Any -dbg flag that I can set to give more information on this?


Try "-dbg files".

JMarc



Re: $$e not set on import --> import of .Rnw (knitr) fails

2012-10-18 Thread Scott Kostyshak
On Thu, Oct 18, 2012 at 8:18 AM, Jean-Marc Lasgouttes
 wrote:
> Le 18/10/2012 14:02, Scott Kostyshak a écrit :
>
>> Ah, then I don't understand how LyX handles imports. The Customization
>> manual does not talk about importing. Doesn't LyX use the converters
>> to convert the file to LaTeX and then use tex2lyx to import the tex
>> file?
>
>
> Normally, the importation is done by tex2lyx using the -n flag, but I think
> that this support needs to be updated to the new world of module based
> literate programming.
>
> The old way this "noweb mode" works is
> 1/ ensure that the class name is literate-something (now it would be ensure
> that some module is loaded and the module name should be passed to tex2lyx)
>
> 2/ when a layout starts with <<, change it to a layout with name "Scrap".
> This could be OK because the Sweave/knitr modules declare Scrap as a synonym
> for Chunk.
>
> 3/ transform [[something]] to ERT. I do not know what this is good for,
> presumably a noweb-only thing.

OK, thanks for the explanation.

>>
>>> What is the difference between the Rnw files when you do this change?
>>
>>
>> No difference. In the recipe for reproducing, steps (1) and (2) are
>> the same.
>
>
> You mean that the Rnw files are the same in the two cases? This is weird.

Yes, the only thing that changes is what I have as the Converter for
Rnw (knitr) to LaTeX (plain). Is there some other output that I can
send? Any -dbg flag that I can set to give more information on this?

Thanks,

Scott


Re: $$e not set on import --> import of .Rnw (knitr) fails

2012-10-18 Thread Jean-Marc Lasgouttes

Le 18/10/2012 14:02, Scott Kostyshak a écrit :

Ah, then I don't understand how LyX handles imports. The Customization
manual does not talk about importing. Doesn't LyX use the converters
to convert the file to LaTeX and then use tex2lyx to import the tex
file?


Normally, the importation is done by tex2lyx using the -n flag, but I 
think that this support needs to be updated to the new world of module 
based literate programming.


The old way this "noweb mode" works is
1/ ensure that the class name is literate-something (now it would be 
ensure that some module is loaded and the module name should be passed 
to tex2lyx)


2/ when a layout starts with <<, change it to a layout with name 
"Scrap". This could be OK because the Sweave/knitr modules declare Scrap 
as a synonym for Chunk.


3/ transform [[something]] to ERT. I do not know what this is good for, 
presumably a noweb-only thing.



What is the difference between the Rnw files when you do this change?


No difference. In the recipe for reproducing, steps (1) and (2) are
the same.


You mean that the Rnw files are the same in the two cases? This is weird.

JMarc



Re: $$e not set on import --> import of .Rnw (knitr) fails

2012-10-18 Thread Scott Kostyshak
On Thu, Oct 18, 2012 at 3:46 AM, Jean-Marc Lasgouttes
 wrote:
> Le 18/10/12 01:49, Scott Kostyshak a écrit :
>
>>> Stupid question; where is importation of knitr files defined in
>>> converters?
>>
>>
>> Rnw (knitr) -> latex (plain)
>> The converter is currently:
>> Rscript --verbose --no-save --no-restore $$s/scripts/lyxknitr.R $$p$$i
>> $$p$$o $$e $$r
>> When I change this to the following, import works:
>> Rscript --verbose --no-save --no-restore $$s/scripts/lyxknitr.R $$p$$i
>> $$p$$o ISO-8859-15 $$r
>
>
> But this is a converter for export, not import.

Ah, then I don't understand how LyX handles imports. The Customization
manual does not talk about importing. Doesn't LyX use the converters
to convert the file to LaTeX and then use tex2lyx to import the tex
file?

> What is the difference between the Rnw files when you do this change?

No difference. In the recipe for reproducing, steps (1) and (2) are
the same. To get it to import I only substitute for $$e before step
(3) (importing).

Scott


Re: $$e not set on import --> import of .Rnw (knitr) fails

2012-10-18 Thread Jean-Marc Lasgouttes

Le 18/10/12 01:49, Scott Kostyshak a écrit :

Stupid question; where is importation of knitr files defined in converters?


Rnw (knitr) -> latex (plain)
The converter is currently:
Rscript --verbose --no-save --no-restore $$s/scripts/lyxknitr.R $$p$$i
$$p$$o $$e $$r
When I change this to the following, import works:
Rscript --verbose --no-save --no-restore $$s/scripts/lyxknitr.R $$p$$i
$$p$$o ISO-8859-15 $$r


But this is a converter for export, not import. What is the difference 
between the Rnw files when you do this change?


JMarc



Re: $$e not set on import --> import of .Rnw (knitr) fails

2012-10-17 Thread Scott Kostyshak
On Wed, Oct 17, 2012 at 6:52 PM, Jean-Marc Lasgouttes
 wrote:
> Le 17/10/12 06:09, Scott Kostyshak a écrit :
>
>> I have this problem on master and 2.0.x.
>>
>> An empty $$e variable is being passed to the converter script on
>> import because the document is not open yet:
>> command = subst(command, token_encoding, buffer ?
>> buffer->params().encoding().iconvName() : string());
>>
>> Should $$e be set to the default encoding of a new document?
>>
>> Or is this something that the converter script should deal with?
>>
>> To reproduce:
>> 1. Open examples/knitr.lyx
>> 2. Export to Rnw (knitr)
>> 3. Import the Rnw (knitr) file
>>
>> I get an error after (3) because lyxknitr.R is expecting a non-empty
>> $$e argument.
>
>
> Stupid question; where is importation of knitr files defined in converters?

Rnw (knitr) -> latex (plain)
The converter is currently:
Rscript --verbose --no-save --no-restore $$s/scripts/lyxknitr.R $$p$$i
$$p$$o $$e $$r
When I change this to the following, import works:
Rscript --verbose --no-save --no-restore $$s/scripts/lyxknitr.R $$p$$i
$$p$$o ISO-8859-15 $$r

Scott


Re: $$e not set on import --> import of .Rnw (knitr) fails

2012-10-17 Thread Jean-Marc Lasgouttes

Le 17/10/12 06:09, Scott Kostyshak a écrit :

I have this problem on master and 2.0.x.

An empty $$e variable is being passed to the converter script on
import because the document is not open yet:
command = subst(command, token_encoding, buffer ?
buffer->params().encoding().iconvName() : string());

Should $$e be set to the default encoding of a new document?

Or is this something that the converter script should deal with?

To reproduce:
1. Open examples/knitr.lyx
2. Export to Rnw (knitr)
3. Import the Rnw (knitr) file

I get an error after (3) because lyxknitr.R is expecting a non-empty
$$e argument.


Stupid question; where is importation of knitr files defined in converters?

JMarc



$$e not set on import --> import of .Rnw (knitr) fails

2012-10-16 Thread Scott Kostyshak
I have this problem on master and 2.0.x.

An empty $$e variable is being passed to the converter script on
import because the document is not open yet:
command = subst(command, token_encoding, buffer ?
buffer->params().encoding().iconvName() : string());

Should $$e be set to the default encoding of a new document?

Or is this something that the converter script should deal with?

To reproduce:
1. Open examples/knitr.lyx
2. Export to Rnw (knitr)
3. Import the Rnw (knitr) file

I get an error after (3) because lyxknitr.R is expecting a non-empty
$$e argument.