Skip to content

Bug: mislabeling of used packages in the logs due to get_used_functions #272

@AbhaySThakur

Description

@AbhaySThakur

What happened?

When using logrx::axecute() to execute R code, a case was detected when using functions with the same name across different packages, the system fails to recognize correct package that has the assignment operator overload.
This issue occurs when a function exists in multiple packages but only one package implements the assignment operator overload version (function<-).

Package Comparison

# common package: has operator overload function
ls("package:common", pattern = "labels")
# [1] "labels<-"

# base package: no operator overload function
ls("package:base", pattern = "labels")
#> [1] "labels"         "labels.default"

Consider below code reprex that works only with common package not with base package, I have intentionally scoped the object to call correct packages to remove any ambiguity and then compare it with the Reproducible example in next section where it wrongly classifies the package.
Using Direct Package Reference
to demonstrate code only works for common package and errors for base package.

library("common")
df <- data.frame(a =1, b=2)

# Works with common package label operator overload for dataframes
common::labels(df) <- list(a="t1",b="t2")
# Fails with base package as expected (no assignment operator overload)
base::labels(df)   <- list(a="t1",b="t2")
#> Error in base::labels(df) <- list(a = "t1", b = "t2"): object 'labels<-' not found

Created on 2025-08-29 with reprex v2.1.1

NOTE: please compare this result with reproducible section where code works but function gets classified incorrectly to base package.

Session Information

No response

Reproducible Example

Wrong classification issue example, please compare below output with code in What happened section.
labels<- is getting mapped to non-existent base package instead of common package.

# Temporary work area
tmpDir <- tempdir()
rcode <- file.path(tmpDir, "test2.R")
rlog  <- file.path(tmpDir, "test2.log")

# Write code that will generate an error to the test file
rcode_text <- c(
  "library(common)",
  "df <- data.frame(a =1, b=2)",
  "labels(df) <- list(a = 'A1',b = 'B1')",
  "labels(df)",
  "str(df)"
)
writeLines(rcode_text, con = rcode)

logrx:::get_used_functions(rcode)
#> # A tibble: 5 × 2
#>   function_name library      
#>   <chr>         <chr>        
#> 1 library       package:base 
#> 2 data.frame    package:base 
#> 3 labels        package:base 
#> 4 list          package:base 
#> 5 str           package:utils

Created on 2025-08-29 with reprex v2.1.1
Running logrx::axecute(rcode) generates log file which incorrectly classifies label the function to base packge.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions