Missing fragment names in confusing R codec

When used Stanglein a document, the Sweaveoutput includes a comment that gives the name of the fragment. This is incredibly useful in setting up learning to orient students in code when they cut and paste. However, when I use knitrto generate code .Rfrom .Rnw, package names are not included (at least I see):

knit('example.Rnw',tangle=TRUE)

I could run Stanglein a document written for knitr, except that there are incompatibilities in the chunk arguments, which exclude the launch Stanglewithout errors.

Is there a way to force knitrcomments to be created in convoluted Rcode that includes block names (and / or numbers) like native Stangle?

+4
source share
1 answer

Thanks @kohske (I just figured it out for myself ...)

purl()has an argument documentationthat is set to 1 by default (1 = add block headers to code; 0 does nothing, 2 adds block headers as roxygen comments). If you want to stick knit(.,tangle=TRUE), you just need opts_knit$set(documentation=1)to get confused.

+5
source

Source: https://habr.com/ru/post/1523703/


All Articles