Skip to content

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

maelle
Copy link
Contributor

@maelle maelle commented May 14, 2024

No description provided.

Copy link
Contributor

aviator-app bot commented May 14, 2024

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This pull request is currently open (not queued).

How to merge

To merge this PR, comment /aviator merge or add the mergequeue label.


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.

@szhorvat
Copy link
Member

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))
Copy link
Contributor Author

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()

@maelle maelle requested a review from krlmlr May 14, 2024 11:28
@maelle
Copy link
Contributor Author

maelle commented May 14, 2024

@szhorvat thanks! Yes, I'm hoping the revdeps checks would help with that. If this breaks too many things, I won't merge it.

@szhorvat
Copy link
Member

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.

@maelle maelle marked this pull request as draft May 14, 2024 11:35
@maelle
Copy link
Contributor Author

maelle commented Mar 25, 2025

@schochastics curious to hear what you think about this. We might also close the PR.

@schochastics
Copy link
Contributor

I think this PR is a good idea, because it forces user to be rational on naming attributes.
But given that the reprex below currently works, I am not sure if we are opening some pandoras box with it?

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

@maelle
Copy link
Contributor Author

maelle commented Mar 27, 2025

set_graph_attr should also use the assert function

Copy link
Contributor

@krlmlr krlmlr left a 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 .

@krlmlr krlmlr changed the title refactor: use assert_character() instead of as.character() refactor: use assert_character() instead of as.character() Apr 3, 2025
@krlmlr
Copy link
Contributor

krlmlr commented Apr 3, 2025

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
Copy link
Contributor Author

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.

@@ -0,0 +1,7 @@
assert_character <- function(x, name = "name", call = rlang::caller_env()) {
Copy link
Contributor Author

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

@maelle
Copy link
Contributor Author

maelle commented Apr 9, 2025

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)?

can we decide after we've seen the revdeps results?

Copy link
Contributor

@krlmlr krlmlr left a 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?

@maelle maelle marked this pull request as ready for review May 13, 2025 11:25
@maelle maelle changed the title refactor: use assert_character() instead of as.character() refactor: use check_string() instead of as.character() May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants