0

I have a private R package on github that I have made.

I make use of !!rlang::sym(function_argument) frequently to accept inputs from functions and use with tidyverse.

For example:

example_function = function(x){

new = mtcars %>% arrange(desc(!!rlang::sym(x))

return(new)
}
 example_function('mpg')

So I have this uploaded to a private github, and then if I go to install it - devtools::install_git('myaccount/myrepo')

when I look at the underlying code in the function

myinstalled_package::example_function

It shows as !(!rlang::sym wherever I had !!rlang::sym. The function still actually works, but again, when I examine the code it doesn't. I looked on github and the code is correct there, it is just when I download it to my computer that I have this really annoying conversion.

I am also seeing other similar changes such as if I had !!each_var := being converted to :=(!(!each_var),

Is there anyway to stop this or why this is happening?

Tung
  • 26,371
  • 7
  • 91
  • 115
runningbirds
  • 6,235
  • 13
  • 55
  • 94
  • 2
    What do you mean by "when I examine the code it doesn't"? – user2554330 Dec 05 '18 at 18:20
  • See this answer to a similar issue I created: https://github.com/jimhester/lookup/issues/19#issuecomment-339762967 – Aurèle Dec 12 '18 at 10:44
  • @Aurèle: Might be worth to paraphrase the solution as a formal answer, so that it can be upvoted and accepted, thus removing the question from the "Unanswered" category. – Artem Sokolov Dec 17 '18 at 18:51

1 Answers1

1

Quoting an answer by Jim Hester on GitHub:

The way R code is displayed by lookup is handled solely by R's internal layout code.

It is recommended you install packages with source references by setting options("keep.source" = TRUE, "keep.source.pkgs" = TRUE) to ensure source references are available. If they are you will find the output is exactly that in the original source file, e.g.

> lookup::lookup(dplyr:::rename.data.frame)
dplyr:::rename.data.frame [S3 method, closure] dataframe.R#L122-125
function(.data, ...) {
  vars <- rename_vars(names(.data), !!! quos(...))
  select_impl(.data, vars)
}
<environment: namespace:dplyr>

// c++ source: src/select.cpp#L79-L86
DataFrame select_impl(DataFrame df, CharacterVector vars) {
  check_valid_colnames(df);
  if (is<GroupedDataFrame>(df)) {
    return select_grouped(GroupedDataFrame(df), SymbolVector(vars), SymbolVector(vars.names()));
  } else {
    return select_not_grouped(df, SymbolVector(vars), SymbolVector(vars.names()));
  }
}

So a way to stop this from happening might be options("keep.source" = TRUE, "keep.source.pkgs" = TRUE).

Aurèle
  • 12,545
  • 1
  • 31
  • 49