DanChaltiel / autoimport

A toolbox to automatically generate @importFrom roxygen tags from R files.
6 stars 1 forks source link

`autoimport()` is doubling the very first line of a file, the function name when function has no Roxygen skeleton #3

Closed cregouby closed 1 year ago

cregouby commented 1 year ago

Current situation

Being inspired by the presentation at RR_2023 Avignon, I've run autoimport() on the code in https://github.com/mlverse/tabnet I'm impressed by the user interface but I get the following issue on few files where the first line of code in the file is the function definition (i.e. function without Roxygen skeleton )

Before autoimport()

file R/pretraining.R is starting with the following lines :

train_batch_un <- function(network, optimizer, batch, config) {
  # forward pass

After autoimport()

file R/pretraining.R is starting with the following lines :

train_batch_un <- function(network, optimizer, batch, config) {
#' @importFrom torch nn_utils_clip_grad_norm_
train_batch_un <- function(network, optimizer, batch, config) {
  # forward pass

where we can see the function definition line is doubled around the Roxygen @importFrom statement

see https://github.com/mlverse/tabnet/blob/9890314421526b2244433ea1f168078fd8feb447/R/dials.R#L1-L3 see https://github.com/mlverse/tabnet/blob/9890314421526b2244433ea1f168078fd8feb447/R/package.R#L1-L3 see https://github.com/mlverse/tabnet/blob/9890314421526b2244433ea1f168078fd8feb447/R/pretraining.R#L1-L3

Reproducible example

# git clone https://github.com/mlverse/tabnet
# cd tabnet
library(autoimport)
autoimport(files = "R/dials.R")
#> Error: './NAMESPACE' does not exist in current working directory ('/tmp/RtmpXgZklI/reprex-301dcf3b5c6d89-pure-tayra').

Created on 2023-06-25 with reprex v2.0.2

Session info

``` r R version 4.3.0 (2023-04-21) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 22.04.2 LTS Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0 locale: [1] LC_CTYPE=fr_FR.UTF-8 LC_NUMERIC=C LC_TIME=fr_FR.UTF-8 LC_COLLATE=fr_FR.UTF-8 [5] LC_MONETARY=fr_FR.UTF-8 LC_MESSAGES=fr_FR.UTF-8 LC_PAPER=fr_FR.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C time zone: Europe/Paris tzcode source: system (glibc) attached base packages: [1] stats graphics grDevices datasets utils methods base other attached packages: [1] tabnet_0.4.0.9000 testthat_3.1.9 shiny_1.7.4 bit_4.0.5 autoimport_0.0.1.9000 [6] recipes_1.0.6 lubridate_1.9.2 forcats_1.0.0 stringr_1.5.0 dplyr_1.1.2 [11] purrr_1.0.1 readr_2.1.4 tidyr_1.3.0 tibble_3.2.1 ggplot2_3.4.2 [16] tidyverse_2.0.0 data.tree_1.0.0 data.table_1.14.8 loaded via a namespace (and not attached): [1] remotes_2.4.2 rlang_1.1.1 magrittr_2.0.3 compiler_4.3.0 callr_3.7.3 vctrs_0.6.3 [7] profvis_0.3.8 pkgconfig_2.0.3 crayon_1.5.2 fastmap_1.1.1 backports_1.4.1 ellipsis_0.3.2 [13] utf8_1.2.3 promises_1.2.0.1 rmarkdown_2.22 prodlim_2023.03.31 sessioninfo_1.2.2 tzdb_0.4.0 [19] ps_1.7.5 torch_0.10.0 reprex_2.0.2 xfun_0.39 cachem_1.0.8 progress_1.2.2 [25] later_1.3.1 parallel_4.3.0 prettyunits_1.1.1 R6_2.5.1 stringi_1.7.12 parallelly_1.36.0 [31] pkgload_1.3.2 rpart_4.1.19 brio_1.1.3 Rcpp_1.0.10 knitr_1.43 future.apply_1.11.0 [37] usethis_2.2.1 httpuv_1.6.11 Matrix_1.5-4.1 splines_4.3.0 nnet_7.3-19 timechange_0.2.0 [43] tidyselect_1.2.0 yaml_2.3.7 rstudioapi_0.14 timeDate_4022.108 codetools_0.2-19 miniUI_0.1.1.1 [49] processx_3.8.1 listenv_0.9.0 pkgbuild_1.4.1 lattice_0.21-8 withr_2.5.0 evaluate_0.21 [55] desc_1.4.2 future_1.32.0 survival_3.5-5 urlchecker_1.0.1 diffviewer_0.1.1 pillar_1.9.0 [61] checkmate_2.2.0 generics_0.1.3 rprojroot_2.0.3 hms_1.1.3 munsell_0.5.0 scales_1.2.1 [67] coro_1.0.3 globals_0.16.2 xtable_1.8-4 bspm_0.5.1 class_7.3-22 glue_1.6.2 [73] clipr_0.8.0 tools_4.3.0 gower_1.0.1 fs_1.6.2 grid_4.3.0 ipred_0.9-14 [79] devtools_2.4.5 colorspace_2.1-0 cli_3.6.1 fansi_1.0.4 lava_1.7.2.1 gtable_0.3.3 [85] digest_0.6.31 htmlwidgets_1.6.2 memoise_2.0.1 htmltools_0.5.5 lifecycle_1.0.3 hardhat_1.3.0 [91] mime_0.12 bit64_4.0.5 MASS_7.3-60 ```
DanChaltiel commented 1 year ago

Hi C, It was very nice to talk with you at RR2023, and I'm glad you tried my package :-) I think both your issues are corrected now, but don't hesitate to reopen if not.