There is one more requirement for tangling with comments, that is the
presence of a :comments header argument. If this argument is not set
for a code block then that code block *will not* be tangled with
comments regardless of the value of `org-babel-tangle-w-comments'.

That explains.

You can set this variable to default to true for R code blocks with the
following

(add-to-list 'org-babel-default-header-args:R '(:comments . "yes"))

OK - it is working.What I actually did, was to add

#+BABEL: :comments yes

to the headers of the file, so I can control it on a file basis.

Hope this helps.

Definitely.

I think that moving forward it might make sense to remove the
org-babel-tangle-w-comments variable, as it's confusing to have two
points of control for comments during tangling. Also, it looks like I
need to add the :comments header argument to the babel documentation.

Both points agreed.

In addition: is it possible to customize the format for all comments (on a per file basis and / or a per block basis)? i.e. I don't need the file name, as all blocks are coming from one file. I know about

#+srcname: <name>

but is there a variable for the line number (I guess that is covered by the request posted in another thread) one could use?

Also, would it be possible to include a link in the comment block, so that clicking on that link actually opens the org-file file at the location of the source block? That would make editing the code really easy.

Thanks for helping to sort some of these issues out!

Pleasure - I use them and I profit when they are sorted out. In addition: I think org-mode and babel deserve it - they are great tools for programming in R.

> Hi
>
> I am trying to use "tangle with comments". Based on a previous thread, I
> set org-babel-tangle-w-comments to t with
> (setq org-babel-tangle-w-comments t)
> in my emacs.org file.
>
> The variable is actually set to 1 - I checked vie C-h - v
>
> But nothing is changing in the tangled file? Am I doing something wrong? Or
> are comments not supported in R in org-babel?
>
> I attach a small testfile.
>
> Cheers,
>
> Rainer