I am trying to read a csv file that has barcodes in the first column, but when R gets it into a data.frame, it converts “1665535004661” to “1.67E+12”. Is there a way to preserve this number in an integer format? I tried assigning a class of “double”, but that didn’t work, nor did assigning a class of “character”. Once it is in the 1.67E+12 format any attempt to convert it back to an integer returns “167000000000”.

See, the numbers were there all along. They don't get lost unless you have a really large number of digits. Sorting on what you brought in will work fine and you can just explicitly call print() with the digits option to see your data.frame instead of implicitly by typing the name.

This essentially overrides the method I discuss below with options(). As a point of reference, one should read and heed the warning in ?print.default as the implementation at >= 16 digits starts to become a platform specific issue as the implementation of sprintf() begins to differ based on the underlying C code.
–
ChaseMay 23 '12 at 3:29

The same is true if you use options(). It's only an output default. I think it would be best if you were explicit about that in your answer. As it is that's rather vague. Trying to read it naive I'm wondering if the digits option just changes how many digits are retained, how they're read in?... what?
–
JohnMay 23 '12 at 5:30

Good point - edited my answer to be more explicit about that. Feel free to tweak further if you think necessary. Cheers! - Chase
–
ChaseMay 24 '12 at 3:42

Alternatively (and for other uses), you can specify the digits variable under options(). The default is 7 digits and the acceptable range is 1-22. To be clear, setting this option in no way changes or alters the underlying data, it merely controls how it is displayed on screen when printed. From the help page for ?options:

controls the number of digits to print when printing numeric values. It is a suggestion only.
Valid values are 1...22 with default 7. See the note in print.default about values greater than
15.

To flesh this out completely and to account for the cases when setting a global setting is not preferable, you can specify digits directly as an argument to print(foo, digits = bar). You can read more about this under ?print.default. This is what John describes in his answer so credit should go to him for illuminating that nuance.

Since you are not performing arithmetic on this value, character is appropriate. You can use the colClasses argument to set various classes for each column, which is probably better than using all character.