Get full properties of R object
str
(with optionally passedvec.len
,nhcar.max
etc. arguments) should be fine. E.g.:> str(mtcars, vec.len=Inf) 'data.frame': 32 obs. of 11 variables: $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26 30.4 15.8 19.7 15 21.4 $ cyl : num 6 6 4 6 8 6 8 4 4 6 6 8 8 8 8 8 8 4 4 4 4 8 8 8 8 4 4 4 8 6 8 4 $ disp: num 160 160 108 258 360 225 360 146.7 140.8 167.6 167.6 275.8 275.8 275.8 472 460 440 78.7 75.7 71.1 120.1 318 304 350 400 79 120.3 95.1 351 145 301 121 $ hp : num 110 110 93 110 175 105 245 62 95 123 123 180 180 180 205 215 230 66 52 65 97 150 150 245 175 66 91 113 264 175 335 109 $ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 3.92 3.07 3.07 3.07 2.93 3 3.23 4.08 4.93 4.22 3.7 2.76 3.15 3.73 3.08 4.08 4.43 3.77 4.22 3.62 3.54 4.11 $ wt : num 2.62 2.88 2.32 3.21 3.44 3.46 3.57 3.19 3.15 3.44 3.44 4.07 3.73 3.78 5.25 5.42 5.34 2.2 1.61 1.83 2.46 3.52 3.44 3.84 3.85 1.94 2.14 1.51 3.17 2.77 3.57 2.78 $ qsec: num 16.5 17 18.6 19.4 17 20.2 15.8 20 22.9 18.3 18.9 17.4 17.6 18 18 17.8 17.4 19.5 18.5 19.9 20 16.9 17.3 15.4 17.1 18.9 16.7 16.9 14.5 15.5 14.6 18.6 $ vs : num 0 0 1 1 0 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 0 1 0 0 0 1 $ am : num 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 $ gear: num 4 4 4 3 3 3 3 4 4 4 4 3 3 3 3 3 3 4 4 4 3 3 3 3 3 4 5 5 5 5 5 4 $ carb: num 4 4 1 1 2 1 4 2 2 4 4 3 3 3 4 4 4 1 2 1 1 2 2 4 2 1 2 2 4 6 8 2
I you'd want to compare the two R objects from line-to-line, you might try to diff the
dput
ed version of the two objects.> dput(mtcars, file = 'mtcars') > mtcars2 <- mtcars > mtcars2$am <- 0 > dput(mtcars2, file = 'mtcars2') > system('diff mtcars mtcars2') 23,25c23,25 < 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1), am = c(1, < 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, < 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1), gear = c(4, 4, 4, 3, --- > 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1), am = c(0, > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), gear = c(4, 4, 4, 3,
Another method might be to check the hashes of the objects or its parts, short example:
> library(digest) > apply(mtcars, 2, digest) mpg cyl "6b33fae3fd79bb2081e21798c7001c1f" "fb8453e241dd708f9b17c412e94ab884" disp hp "feae4e282905d11380533c3cfa3fa997" "2afa2fea47856dc4fa23eb543f1d08a4" drat wt "345237ccc9e9b4f523ccdfde31e2f7c5" "558e5730ef0af2f50f23fe86363855ed" qsec vs "e777220d1d85545fd98767bb39f10967" "16ff5701471198a294b5c45a90dad3ca" am gear "abf0f4ab68322a6dd0fc078570892202" "7f9bb11d36a531de7ab0d6e71fd532c9" carb "793a7b0812e7597d508be29fc432ff49"
Here you would get the hash for each column in
mtcars
which could be compared with a similar data frame and see which column differs, e.g.:> apply(mtcars, 2, digest) == apply(mtcars2, 2, digest) mpg cyl disp hp drat wt qsec vs am gear carb TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE
user1165199
Updated on June 04, 2022Comments
-
user1165199 almost 2 years
There is a function I have used before to get the full properties of an object in R (I used it before to find out why two dataframes which looked identical failed the checkEquals RUnit check).
The structure (
str()
) and attributes (attributes()
) look identical. Can anyone point me in the right direction as to what the function which shows the full properties of an object is please?