Retain comments inside R expression

55 Views Asked by At
my_expr <- expr({
  # this is a comment
  this_is_code
})
my_expr

returns:

{
  this_is_code
}

But i'd like it to return:

{
  # this is a comment
  this_is_code
}

Is retaining the comment possible using rlang?

1

There are 1 best solutions below

0
On BEST ANSWER

The comment is already retained, it just doesn't get printed to the console. Check out attr(my_expr, "wholeSrcref").