roxyglobals icon indicating copy to clipboard operation
roxyglobals copied to clipboard

Only include unique results?

Open jimhester opened this issue 2 years ago • 2 comments

Currently roxyglobals duplicates globals that are registered in multiple files. I think it would probably be preferred to only keep the first instance of each name.

jimhester avatar Jan 07 '22 15:01 jimhester

Duplicating registered globals for each function is intentional. Each global explicitly indicates which function defined it, which is useful for debugging (this was implemented for #3).

utils::globalVariables() drops the duplicates via unique(), so I think there should be little overhead (I haven't observed it being an issue at least)?

Perhaps what we could do, is make globals unique, but indicate which functions that defined the globals via comments? The globals.R will get larger this way, but the vector itself would be smaller.

Example (pulled from {rdeck}

# Generated by roxyglobals: do not edit by hand

utils::globalVariables(c(
  # <add_h3_cluster_layer>
  # <add_h3_hexagon_layer>
  "hexagon", 
  # <add_geojson_layer>
  # <add_icon_layer>
  # <add_mvt_layer>
  "icon", 
  # <add_path_layer>
  # <add_trips_layer>
  "path", 
  # <add_column_layer>
  # <add_contour_layer>
  # <add_cpu_grid_layer>
  # <add_gpu_grid_layer>
  # <add_grid_cell_layer>
  # <add_grid_layer>
  # <add_heatmap_layer>
  # <add_hexagon_layer>
  # <add_icon_layer>
  # <add_point_cloud_layer>
  # <add_polygon_layer>
  # <add_scatterplot_layer>
  # <add_scenegraph_layer>
  # <add_screen_grid_layer>
  # <add_simple_mesh_layer>
  # <add_solid_polygon_layer>
  # <add_text_layer>
  "position", 
  # <add_arc_layer>
  # <add_great_circle_layer>
  # <add_line_layer>
  "source_position", 
  # <add_arc_layer>
  # <add_great_circle_layer>
  # <add_line_layer>
  "target_position", 
  # <add_geojson_layer>
  # <add_mvt_layer>
  # <add_text_layer>
  "text", 
  # <add_trips_layer>
  "timestamps", 
  # <add_s2_layer>
  "token", 
  NULL
))

anthonynorth avatar Jan 10 '22 06:01 anthonynorth

That seems like a good solution to me.

jimhester avatar Jan 10 '22 15:01 jimhester

Finally got around to actioning this. Unique globals is configured with Config/roxyglobals/unique. Utility to change: roxyglobals::options_set_unique(value).

anthonynorth avatar Jul 29 '23 02:07 anthonynorth