itdepends icon indicating copy to clipboard operation
itdepends copied to clipboard

Error: $ operator is invalid for atomic vectors in itdepends::dep_usage_proj

Open balthasars opened this issue 6 years ago • 2 comments

Hi there!

Thanks so much for the cool package, it works great for packages!

I ran into some issues with getting itdepends::dep_usage_proj() to work for projects, I generally don't get much further than this:

itdepends::dep_usage_proj()
#> Error: $ operator is invalid for atomic vectors

Created on 2019-02-06 by the reprex package (v0.2.1)

Any ideas on how I can resolve this?

Thanks so much in advance for any pointers!

balthasars avatar Feb 06 '19 08:02 balthasars

The function expects projects to be similarly structured as packages, otherwise it will not work:

> itdepends::dep_usage_proj

function (path = ".") 
{
    files <- proj_files(path)
    default_pkgs <- c("base", strsplit(Sys.getenv("R_DEFAULT_PACKAGES"), 
        ",")[[1]])
    pkgs <- c(default_pkgs, unlist(lapply(files, requirements::req_file)))
    funs <- purrr::map(pkgs, pkg_ls)
    fun_to_pkg <- stats::setNames(rep(pkgs, lengths(funs)), unlist(funs, 
        use.names = FALSE))
    pkg_calls <- do.call(rbind, c(lapply(files, dep_usage_file), 
        make.row.names = FALSE, stringsAsFactors = FALSE))
    missing_pkg <- pkg_calls$pkg == "NA"
    pkg_calls$pkg[missing_pkg] <- fun_to_pkg[pkg_calls$fun[missing_pkg]]
    tibble::as.tibble(pkg_calls)
}
<bytecode: 0x7fa96e46f558>
<environment: namespace:itdepends>

and inside that, the dir() function appears to only look for folders called R, tests and inst:

> itdepends:::proj_files
function (path = ".") 
{
    path <- proj_find(path)
    dir(path = file.path(path, c("R", "tests", "inst")), pattern = "[.][Rr](?:md)?$", 
        recursive = TRUE, full.names = TRUE)
}
<bytecode: 0x7fa9514ec678>
<environment: namespace:itdepends>

How can it be adapted such that projects with different file structures can also be indexed?

balthasars avatar Feb 06 '19 12:02 balthasars

This is also an issue if a package contains zero functions - which may well be the case for data packages.

andrewdolman avatar Jan 06 '20 12:01 andrewdolman