Find Out Available Usernames with R

[This article was first published on Yihui Xie, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Update on 2013/01/05: Xiao Nan in the comments pointed out that apply(combn(letters, 2), 2, paste0, collapse = '') was wrong for all two-letter usernames, and indeed it was. It is not a combination problem. Now I use his elegant outer() solution. One can also use expand.grid(letters, letters).

Github decided to take off their downloads service, and I was very unhappy with this decision. This means I have to migrate several files to other places, and update links accordingly. I saw Bitbucket still provides the service, so I want to migrate my files there.

Sadly my name yihui was already taken on Bitbucket, so I hoped I could get a short name, which made me think how I could check the availability of a username via programming, and here was my solution with the RCurl package:

library<span class="p">(</span>RCurl<span class="p">)</span>
test_user <span class="o">=</span> <span class="kr">function</span><span class="p">(</span>site <span class="o">=</span> <span class="s">'https://bitbucket.org/'</span><span class="p">,</span>
                     candidates <span class="o">=</span> c<span class="p">(</span><span class="m">0</span><span class="o">:</span><span class="m">9</span><span class="p">,</span> letters<span class="p">))</span> <span class="p">{</span>
  <span class="kr">for</span> <span class="p">(</span>i <span class="kr">in</span> candidates<span class="p">)</span> <span class="p">{</span>
    <span class="kr">if</span> <span class="p">(</span><span class="o">!</span>url.exists<span class="p">(</span>paste0<span class="p">(</span>site<span class="p">,</span> i<span class="p">)))</span> message<span class="p">(</span>i<span class="p">)</span>
    Sys.sleep<span class="p">(</span>runif<span class="p">(</span><span class="m">1</span><span class="p">,</span> <span class="m">0</span><span class="p">,</span> <span class="m">.1</span><span class="p">))</span> <span class="c1"># be nice</span>
  <span class="p">}</span>
<span class="p">}</span>
<span class="c1"># examples</span>
test_user<span class="p">()</span>
<span class="c1"># two-letter names</span>
test_user<span class="p">(</span>candidates <span class="o">=</span> as.vector<span class="p">(</span>outer<span class="p">(</span>letters<span class="p">,</span> letters<span class="p">,</span> <span class="s">'paste0'</span><span class="p">)))</span>
<span class="c1"># check github</span>
test_user<span class="p">(</span><span class="s">'https://github.com/'</span><span class="p">)</span>

As of the time of this blog post, there are no two-letter usernames left on Github, but some are still available on Bitbucket, e.g. by and eq, etc, and the number 4 is also available.

To leave a comment for the author, please follow the link and comment on their blog: Yihui Xie.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)