How to shorten code for “visRemoveNodes” using loop

I have constructed multiple protein - protein networks for diseases in shiny app and I ploted them using visnetwork. I found the articulation points for each network and I want to remove them.

My code for a disease looks like this:

 output$plot54 <- renderVisNetwork({
        alsex <- as.matrix(alsex)
        sel1 <- alsex[,1]
        sel2 <- alsex[,2]
        n10 <- unique(c(sel1,sel2))
        n10 <-
        colnames(n10) <- "id"
        ed10 <-
        colnames(ed10) <- c("from", "to", "width")
        g <- graph_from_data_frame(ed10) 

        nodes4 <- data.frame(n10, color = ifelse(n10$id=="CLEC4E"|n10$id=="ACE2"|n10$id=="MYO7A"|n10$id=="HSPB4"
        visNetwork(nodes4, ed10, main = "Articulation Points") %>%
          visNodes (color = list(highlight = "pink"))%>%
          visOptions(highlightNearest = list(enabled = T, hover = T), 
                     nodesIdSelection = T)%>%
          visInteraction(keyboard = TRUE)

        visNetworkProxy("plot54") %>%
          visRemoveNodes(id="CLEC4E")%>%visRemoveEdges(id = "CLEC4E")%>%
          visRemoveNodes(id="ACE2")%>%visRemoveEdges(id = "ACE2")%>%
          visRemoveNodes(id="MYO7A")%>%visRemoveEdges(id = "MYO7A")%>%
          visRemoveNodes(id="HSPB4")%>%visRemoveEdges(id = "HSPB4")%>%
          visRemoveNodes(id="EXOSC3")%>%visRemoveEdges(id = "EXOSC3")%>%
          visRemoveNodes(id="RBM45")%>%visRemoveEdges(id = "RBM45")%>% 
          visRemoveNodes(id="SPAST")%>%visRemoveEdges(id = "SPAST")%>%
          visRemoveNodes(id="ALMS1")%>%visRemoveEdges(id = "ALMS1")%>%
          visRemoveNodes(id="PIGQ")%>%visRemoveEdges(id = "PIGQ")%>%
          visRemoveNodes(id="CDC27")%>%visRemoveEdges(id = "CDC27")%>%
          visRemoveNodes(id="GFM1")%>%visRemoveEdges(id = "GFM1")%>%
          visRemoveNodes(id="UTRN")%>%visRemoveEdges(id = "UTRN")%>%
          visRemoveNodes(id="RAB7B")%>%visRemoveEdges(id = "RAB7B")%>%
          visRemoveNodes(id="GSN")%>%visRemoveEdges(id = "GSN")%>%
          visRemoveNodes(id="VAPA")%>%visRemoveEdges(id = "VAPA")%>%
          visRemoveNodes(id="GLE1")%>%visRemoveEdges(id = "GLE1")%>%
          visRemoveNodes(id="FA2H")%>%visRemoveEdges(id = "FA2H")%>%
          visRemoveNodes(id="HSPA4")%>%visRemoveEdges(id = "HSPA4")%>%
          visRemoveNodes(id="SNCA")%>%visRemoveEdges(id = "SNCA")%>%
          visRemoveNodes(id="RAB5A")%>%visRemoveEdges(id = "RAB5A")%>%
          visRemoveNodes(id="SETX")%>%visRemoveEdges(id = "SETX")


  g <- graph_from_data_frame(ed10) 

I found the articulation points, and I marked them with red color using ifelse as you can see in nodes4 vector.

My questions:

  1. How to shorten my code in ifelse using loop, so I don't have to write the articullation points one by one manually.
  2. How to shorten my code in visRemoveNodes and visRemoveEdges using loop, so I don't have to write them one by one manually as well.

Cross posted here, back on July 2nd, with no reply,

From: FAQ: Is it OK if I cross-post?