MayaGans
MayaGans

Reputation: 1845

Retain comments inside R expression

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?

Upvotes: 1

Views: 48

Answers (1)

bcarlsen
bcarlsen

Reputation: 1441

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

Upvotes: 2

Related Questions