For a socket or context using the sub protocol in a publisher/subscriber pattern. Remove a topic from the subscription list.

unsubscribe(con, topic = NULL)



a Socket or Context using the 'sub' protocol.


[default NULL] an atomic type or NULL. The default NULL unsubscribes from all topics (if all topics were previously subscribed).


Invisibly, an integer exit code (zero on success).


Note that if the topic was not previously subscribed to then an 'entry not found' error will result.

To use pub/sub the publisher must:

  • specify mode = 'raw' when sending.

  • ensure the sent vector starts with the topic.

The subscriber should then receive specifying the correct mode.


pub <- socket("pub", listen = "inproc://nanonext")
sub <- socket("sub", dial = "inproc://nanonext")

subscribe(sub, NULL)

send(pub, c("examples", "this is an example"), mode = "raw")
recv(sub, "character")
#> [1] "examples"           "this is an example"
send(pub, "examples will also be received", mode = "raw")
recv(sub, "character")
#> [1] "examples will also be received"
unsubscribe(sub, NULL)
send(pub, c("examples", "this example will not be received"), mode = "raw")
recv(sub, "character")
#> Warning: 8 | Try again
#> 'errorValue' int 8 

subscribe(sub, 2)
send(pub, c(2, 10, 10, 20), mode = "raw")
recv(sub, "double", keep.raw = FALSE)
#> [1]  2 10 10 20