You could use dunn.test() to calculate the unadjusted p-values (you have to provide a method before it will perform adjustments for multiplicity, otherwise the p-values are unadjusted and so not penalised for groups not involved in that particular pairwise comparison), which you can then use however you wish, e.g. Bonferroni or Holm's, but only making the adjustments for the comparisons of interest. The approaches for the adjustment methods in dunn.test() are all sufficiently well described in its manual for you to do these by hand, but you could also use p.adjust() to do this for you.
Below is a simple example with three groups where group 0 is the control with two treatments to be compared with the control but not with each other. I'm not recommending Bonferroni as a method, but it makes it clear what's going on. If you pass all three p-values to p.adjust(), you get the same adjusted values as from dunn.test(method="bonferroni"), but you can, instead, pass it just the two p-values for the two comparisons that you were interested in.
> mydata.response <- seq(1,9)
> mydata.group <- c(rep(0,3), rep(1,3), rep(2,3))
> cbind(mydata.response, mydata.group)
mydata.response mydata.group
[1,] 1 0
[2,] 2 0
[3,] 3 0
[4,] 4 1
[5,] 5 1
[6,] 6 1
[7,] 7 2
[8,] 8 2
[9,] 9 2
>
> library(dunn.test)
> myresults.unadjusted <- dunn.test(mydata.response, mydata.group)
Kruskal-Wallis rank sum test
data: mydata.response and mydata.group
Kruskal-Wallis chi-squared = 7.2, df = 2, p-value = 0.03
Comparison of mydata.response by mydata.group
(No adjustment)
Col Mean-|
Row Mean | 0 1
---------+----------------------
1 | -1.341640
| 0.0899
|
2 | -2.683281 -1.341640
| 0.0036* 0.0899
alpha = 0.05
Reject Ho if p <= alpha/2
> myresults.adjusted <-dunn.test(mydata.response, mydata.group, method="bonferroni")
Kruskal-Wallis rank sum test
data: mydata.response and mydata.group
Kruskal-Wallis chi-squared = 7.2, df = 2, p-value = 0.03
Comparison of mydata.response by mydata.group
(Bonferroni)
Col Mean-|
Row Mean | 0 1
---------+----------------------
1 | -1.341640
| 0.2696
|
2 | -2.683281 -1.341640
| 0.0109* 0.2696
alpha = 0.05
Reject Ho if p <= alpha/2
> myresults.unadjusted$P
[1] 0.089856247 0.003645179 0.089856247
> myresults.adjusted$P.adjusted
[1] 0.26956874 0.01093554 0.26956874
>
> p.adjust(myresults.unadjusted$P[1:3], method="bonferroni")
[1] 0.26956874 0.01093554 0.26956874
> p.adjust(myresults.unadjusted$P[1:2], method="bonferroni")
[1] 0.179712495 0.007290358