-
-
Notifications
You must be signed in to change notification settings - Fork 206
refactor: use check_string()
instead of as.character()
#1365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Current Aviator status
This pull request is currently open (not queued). How to mergeTo merge this PR, comment
See the real-time status of this PR on the
Aviator webapp.
Use the Aviator Chrome Extension
to see the status of your PR within GitHub.
|
I'm not experienced enough with R to be able to follow the code without considerable time investment, but I wanted to point out that in many cases, numerical vertex IDs or vertex names are auto-converted to characters. This is convenient and probably desirable. I do not know if this change breaks any of the relevant use cases, but it's good to pay attention here. |
name <- gsub("\\s", "_", name) | ||
|
||
on.exit(.Call(R_igraph_finalizer)) | ||
res <- .Call(R_igraph_famous, as.character(name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what could name be given it's been fed to gsub()
@szhorvat thanks! Yes, I'm hoping the revdeps checks would help with that. If this breaks too many things, I won't merge it. |
And just another reminder that our users are not just dependent packages, but also individuals who use igraph for research, often interactively. Unfortunately it is difficult to track this second kind of user, even though IMO they are the majority. |
@schochastics curious to hear what you think about this. We might also close the PR. |
I think this PR is a good idea, because it forces user to be rational on naming attributes. library(igraph)
#>
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:stats':
#>
#> decompose, spectrum
#> The following object is masked from 'package:base':
#>
#> union
g <- sample_gnp(10,0.2)
g$`5` <- 4
g
#> IGRAPH 9a520e7 U--- 10 3 -- Erdos-Renyi (gnp) graph
#> + attr: name (g/c), type (g/c), loops (g/l), p (g/n), 5 (g/n)
#> + edges from 9a520e7:
#> [1] 2--3 1--4 1--8
graph_attr(g,5)
#> [1] 4
delete_graph_attr(g,5)
#> IGRAPH 9a520e7 U--- 10 3 -- Erdos-Renyi (gnp) graph
#> + attr: name (g/c), type (g/c), loops (g/l), p (g/n)
#> + edges from 9a520e7:
#> [1] 2--3 1--4 1--8 Created on 2025-03-25 with reprex v2.1.1 |
set_graph_attr should also use the assert function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I'd prefer using the rlang standalone for checking, wanted to add it for some time now: https://github.com/r-lib/rlang/blob/main/R/standalone-types-check.R .
assert_character()
instead of as.character()
Crazy idea: add a lifecycle compatibility layer that doesn't break existing code (which I'd consider off-label use, but keeping compat is a gesture of goodwill)? |
@@ -10,6 +9,7 @@ | |||
#' @importFrom rlang inject | |||
#' @importFrom rlang warn | |||
#' @importFrom rlang %||% | |||
#' @import rlang |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed for the standalone files (unless we prefer I try to find all function names that need to be namespaced in these files) but I didn't want to remove the lines before as I like the clarity... but maybe I should.
R/utils-assert-character.R
Outdated
@@ -0,0 +1,7 @@ | |||
assert_character <- function(x, name = "name", call = rlang::caller_env()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this uses the rlang thing now
can we decide after we've seen the revdeps results? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Can you please add a test? Do we really need assert_character()
, or does the default arg of check_string()
do the right thing?
assert_character()
instead of as.character()
check_string()
instead of as.character()
No description provided.