mooreryan / featuretable

MIT License
1 stars 1 forks source link

error in RStudio conda environment #4

Closed lingyi-owl closed 1 year ago

lingyi-owl commented 2 years ago

Hi, i am using RStudio from a conda created environment. I installed rlang and featuretable using the introction in the gitpage. the featuretable library was installed and loaded succesfully. I could construct a featuretable object and make a plot using the built-in function. However, i had troubles using the core_microbiome function.

Here is the error:

>  core_microbiome(pond_ft, detection_limit = 20, min_sample_proportion = 0.2)
Error in keep_helpers$expr_has_query_function(rlang::enexpr(predicate)) : 
  TODO NEEDED AN EXPRESSION

Could you help me with this?

Best,

mooreryan commented 2 years ago

Hey could you try an make a minimum reproducible example?

If you install the reprex package you can do something like this:

reprex( { library(featuretable) pond_ft <- ... put code you used to make the feature table here ... core_microbiome(pond_ft, detection_limit = 20, min_sample_proportion = 0.2) },

This sets the working directory so reprex knows where the files are

wd = "bug_reprex",

This gives nice output to paste into GitHub issues

venue = "gh",

This will show me your current session info

session_info = TRUE )



* Then you can zip the `bug_reprex` outdirectory with the input files and send them to me. (Or if there is only one input file needed, just send that.)
* And also paste the reprex output into this GitHub issue so I can try and reproduce your problem.

If at all possible, it is helpful to reduce the size of the input file(s) (eg reduce the number of rows and columns).  If the smaller file also triggers the error, send that instead of the full input file(s).  If it works on the smaller file, then the full file is okay to send.

Let me know if you can do that, and we can go from there!
mooreryan commented 2 years ago

Actually, I have a feeling you may have rlang version >= 1.0. Before you do the other stuff, could you run this R code in your environment and paste the output?

library(rlang)

sessionInfo()

f <- function (predicate) {
  rlang::is_expression(rlang::enexpr(predicate))
}

f(function(x) { x })
lingyi-owl commented 2 years ago

yes the rlang version is 1.0.1. I am not with that computer now but what version of rlang should I use?

mooreryan commented 2 years ago

I think as long as rlang version is < 1.0, it should be okay. There was a change in how the rlang::is_expression in version 1 of rlang that I think could be the cause of your error.

AlexaBennett commented 2 years ago

@mooreryan I am having the same issue and have attempted rolling back rlang to 0.4.12, 0.4.11, 0.4.5, and 0.4.1. All of the attempts result in the same error.

Error in keep_helpers$expr_has_query_function(rlang::enexpr(predicate)) : TODO NEEDED AN EXPRESSION

Edit: Additional context, the command was previously functional when running R v4.0.1 and v4.0.2.

mooreryan commented 2 years ago

Interesting...I have rlang 0.4.10 and I cannot reproduce. Would you mind making a reprex for me @AlexaBennett?

AlexaBennett commented 2 years ago

I loaded the pond_ft since you are familiar with how it should behave with FeatureTable. Let me know if/when you would like me to do the same with my featuretable object

library(featuretable)
load("~/Documents/IMBRE_MCAW_2021/ASV Analysis/data/pond_featuretable.Rdata")
pond_ft
#> <environment: 0x560c115d5b90>
#> attr(,"class")
#> [1] "FeatureTable" "R6"
core_microbiome(pond_ft, detection_limit = 20, min_sample_proportion = 0.2)
#> Error in keep_helpers$expr_has_query_function(rlang::enexpr(predicate)): TODO NEEDED AN EXPRESSION

Created on 2022-05-23 by the reprex package (v2.0.1)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.1.3 (2022-03-10) #> os Fedora Linux 35 (Workstation Edition) #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/New_York #> date 2022-05-23 #> pandoc 2.14.0.3 @ /usr/libexec/rstudio/bin/pandoc/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> cli 3.3.0 2022-04-25 [1] CRAN (R 4.1.3) #> digest 0.6.29 2021-12-01 [1] CRAN (R 4.1.3) #> evaluate 0.15 2022-02-18 [1] CRAN (R 4.1.3) #> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.3) #> featuretable * 0.0.10 2022-04-21 [1] local #> fs 1.5.2 2021-12-08 [1] CRAN (R 4.1.3) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.1.3) #> highr 0.9 2021-04-16 [1] CRAN (R 4.1.3) #> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.3) #> knitr 1.39 2022-04-26 [1] CRAN (R 4.1.3) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.1.3) #> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.3) #> rlang 1.0.2 2022-03-04 [1] CRAN (R 4.1.3) #> rmarkdown 2.14 2022-04-25 [1] CRAN (R 4.1.3) #> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.3) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.1.3) #> stringi 1.7.6 2021-11-29 [1] CRAN (R 4.1.3) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.1.3) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.1.3) #> xfun 0.31 2022-05-10 [1] CRAN (R 4.1.3) #> yaml 2.3.5 2022-02-21 [1] CRAN (R 4.1.3) #> #> [1] /home/lexie/R/x86_64-redhat-linux-gnu-library/4.1 #> [2] /usr/lib64/R/library #> [3] /usr/share/R/library #> #> ────────────────────────────────────────────────────────────────────────────── ```
mooreryan commented 2 years ago

Looks like you have rlang 1.0.2 in your current environment as shown there, which means you're probably running in to the same error as Lingyi was above.

If you are still getting that error with rlang version < 1 then that would probably be a new bug that I can look at, but as shown in your reprex, it looks like the rlang > 1 bug.

I need to adjust the dependencies to mention that featuretable currently requires rlang < 1. Currently to work around it, you will need to downgrade rlang.

AlexaBennett commented 2 years ago

Wow, you are correct. Rstudio is saying v0.4.12 after running install.packages("https://cran.r-project.org/src/contrib/Archive/rlang/rlang_0.4.12.tar.gz", repos=NULL, type="source") yet the session is still 1.0.2! It seems that it wasn't detaching and unloading becasue several other loaded packages have it as a dependency.

Upon starting a new session, the core_microbiome function works.

EDIT: @mooreryan your chunk of code is working with v0.4.12. However, once I move the same code outside of reprex() it breaks.

AlexaBennett commented 2 years ago

@mooreryan TLDR: While further troubleshooting could flush out the details, I got core_microbiome() to work by manually attaching every package listed in the working reprex() chunk.

The packages section differed when calling session_info() in reprex compared to sessionInfo() on the console. Manually loading libraries shown in session_info() but not in sessionInfo() in conjunction with rlang v0.4.12 can be used as a temporary fix on my end. Would you mind explaining how I would go about navigating the repository for this R project? I am not familiar enough with the structure to being to chase down the fix necessary to use rlang >1.0. I primarily work with Python projects where the scripts and all relevant code hit you in the face once you enter bin :sweat_smile:

mooreryan commented 2 years ago

The problem line is this one: https://github.com/mooreryan/featuretable/blob/083f3f506a68762c288fca85a6718eae4d1b2568/R/feature_table.R#L1237

That file has the main R6 class...the other files in that directory are mostly S3 wrappers.

Regarding how to fix it: The info about the breaking change is here (here's the relevant part)

is_expression() now returns FALSE for manually constructed expressions that can't be created by the parser. It used to return TRUE for any calls, including those that contain injected objects.

Consider using is_call() or just remove the expression check. In many cases it is fine letting all objects go through when an expression is expected. For instance you can inject objects directly inside dplyr arguments:

x <- seq_len(nrow(data))
dplyr::mutate(data, col = !!x)

I actually have not thought through the implications for either one of these suggested fixes yet, however. But it could be as easy as removing the expression check like they say. You could try doing that and see what happens. featuretable has a pretty extensive test suite, so you could try running the test suite after you change it and see if anything breaks.

Unfortunately, I don't have any detailed docs to help someone get started with hacking on the codebase, but you will at least need to install some additional deps if you want to run the tests.

mooreryan commented 1 year ago

This is fixed in the latest release.