1) The "i <- 3" is there because I assign the letters "A" and "B" already before the while loop; so then the following assignment will be "C" (i.e., the 3rd element/letter in the "cnames" vector)
2) The 0.15 was included because I thought you wanted to sample only 15% of the nodes. I included "round" to avoid any potential issues with decimals, which I think is already handled by "sample" anyway.
3) In the last 2 lines of code, I increment "i" so a new letter is chosen for the next "compartment". The line before that one is to assign that new compartment only if there is at least 1 sampled neighbor.
4) No, the "unique" line does not remove vertices. The function "adjacent_vertices" returns a list (since "x" can be more than 1 node), so I "unlist" it to make it a numeric vector. I call "unique" to remove any possible duplicates.