简体   繁体   中英

Downloading/installing package from github converting underlying R code

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?

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, eg

 > 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) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM