Wordclouds from ORCiD

I keep seeing nice little wordclouds summarizing research profiles from different groups. I’ve played with them myself. Drawing is simple, but getting the data can be a pain. Now, with the new rorcid package that is made easy. If you don’t already have them, you need the following installed:

## install packages using the following
install.packages("devtools") # to install from github
library(devtools)
install_github("ropensci/rorcid") # to access orcid through R
install.packages(c("tm","wordcloud")) # to draw word clouds

I’ve put a few convenience functions in a gist, so do

Continue reading

Advertisements

Pretty printing progress bars from .Call in R

I wanted to do something that takes a while in C (called from R) and wanted to print a progress bar.

In the R function, I did

pBar <- txtProgressBar( min = 0, max = n, style = 3 )
ret <- .Call("myfunction", arg1, arg2, as.integer(type), pBar, PACKAGE="annotSnpStats")

In the C function, I had

SEXP myfunction(SEXP arg1, SEXP arg2, SEXP Rtype, SEXP pBar) {

  int nprotect=0;
  SEXP utilsPackage, percentComplete;
  PROTECT(utilsPackage = eval(lang2(install("getNamespace"), ScalarString(mkChar("utils"))), R_GlobalEnv));
  PROTECT(percentComplete = allocVector(INTSXP, 1));
  nprotect+=2;
  int *rPercentComplete = INTEGER(percentComplete);
 
  ...

  for(i=0; i<nx; i++) { // index rows of x
  *rPercentComplete = i; //this value increments
  eval(lang4(install("setTxtProgressBar"), pBar, percentComplete, R_NilValue), utilsPackage);
  }

  ... 

  UNPROTECT(nprotect);
  return(myreturn);

}

And … it … just … worked! Happy day.

To see the full R function, go to dups in snp-match.R and the C is in countdiffs in comparisons.c.