R365: Day 6 – str() function

R365: Day 6 – str() function

Im going on a trip today with my wife over to Pt Reyes for camping, so I wanted a pretty quick post for today. Yesterday at lunch, a postdoc in my lab (Christophe Gigot) mentioned that he had previously had problems with R in recognizing whether data that was entered was a set of characters (like the letter O) or a set of numbers (0’s and whatnot). Data analyses within R will not go ahead if your data is mis-entered, so its sometimes important to check that all of your data is in the right format.

Christophe suggested using the R function str(), which is found in the {util} package that comes pre-loaded in most standard versions of R that you download from CRAN. One noticeable catch mentioned in the vignette is that there will not be a normal output as you might expect from other functions. Instead, you will just notice that your code works. They give several examples of how to use str() in their vignette. The options (str(options()) in str() seem to indicate that the function can detect a number of things about your actual computer, including the operating system, where certain programs are (unzip, pdf veiwer, etc), and how you are using R (it recognized that I was working in Rstudio). You also seem to be able to set how you view things, so if you only wanted to view the top 9 entries (you could also use the function header()), you can set what portion of a list you view. You can also set it so that the data wraps around your set screen, or just continues into infinity, or gets truncated at a certain length. I get the weird feeling that I am only viewing the surface of what this package can do. It seems to be able to control the way you view, but it might also control other portions of the output. All in all a very interesting function.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s