{"action":"created","issue":{"url":"https://api.github.com/repos/lgatto/MSnbase/issues/112","repository_url":"https://api.github.com/repos/lgatto/MSnbase","labels_url":"https://api.github.com/repos/lgatto/MSnbase/issues/112/labels{/name}","comments_url":"https://api.github.com/repos/lgatto/MSnbase/issues/112/comments","events_url":"https://api.github.com/repos/lgatto/MSnbase/issues/112/events","html_url":"https://github.com/lgatto/MSnbase/issues/112","id":163483505,"number":112,"title":"all.equal for MSnExp and OnDiskMSnExp","user":{"login":"lgatto","id":384198,"avatar_url":"https://avatars.githubusercontent.com/u/384198?v=3","gravatar_id":"","url":"https://api.github.com/users/lgatto","html_url":"https://github.com/lgatto","followers_url":"https://api.github.com/users/lgatto/followers","following_url":"https://api.github.com/users/lgatto/following{/other_user}","gists_url":"https://api.github.com/users/lgatto/gists{/gist_id}","starred_url":"https://api.github.com/users/lgatto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lgatto/subscriptions","organizations_url":"https://api.github.com/users/lgatto/orgs","repos_url":"https://api.github.com/users/lgatto/repos","events_url":"https://api.github.com/users/lgatto/events{/privacy}","received_events_url":"https://api.github.com/users/lgatto/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/lgatto/MSnbase/labels/feature%20request","name":"feature request","color":"444444"},{"url":"https://api.github.com/repos/lgatto/MSnbase/labels/MSnbase2","name":"MSnbase2","color":"bfdadc"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-07-01T22:21:23Z","updated_at":"2016-07-03T21:53:50Z","closed_at":null,"body":"I am wondering if it wouldn't be a good thing to have an `all.equal` for the different implementations of `MSnExp` objects. While writing unit tests,  I test all accessors one by one, which essentially boils down to writing such a function, which might be useful in the future."},"comment":{"url":"https://api.github.com/repos/lgatto/MSnbase/issues/comments/230177679","html_url":"https://github.com/lgatto/MSnbase/issues/112#issuecomment-230177679","issue_url":"https://api.github.com/repos/lgatto/MSnbase/issues/112","id":230177679,"user":{"login":"lgatto","id":384198,"avatar_url":"https://avatars.githubusercontent.com/u/384198?v=3","gravatar_id":"","url":"https://api.github.com/users/lgatto","html_url":"https://github.com/lgatto","followers_url":"https://api.github.com/users/lgatto/followers","following_url":"https://api.github.com/users/lgatto/following{/other_user}","gists_url":"https://api.github.com/users/lgatto/gists{/gist_id}","starred_url":"https://api.github.com/users/lgatto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lgatto/subscriptions","organizations_url":"https://api.github.com/users/lgatto/orgs","repos_url":"https://api.github.com/users/lgatto/repos","events_url":"https://api.github.com/users/lgatto/events{/privacy}","received_events_url":"https://api.github.com/users/lgatto/received_events","type":"User","site_admin":false},"created_at":"2016-07-03T21:53:50Z","updated_at":"2016-07-03T21:53:50Z","body":"Yes, indeed. The current implementation (untested for now, because of #118)\r\n```r\r\nequalMSnExps <- function(inmem, ondisk, ...) {\r\n    if ((l <- length(inmem)) != length(ondisk)) \r\n        return(\"Objects have different lengths.\")\r\n    if (!isTRUE(fneq <- all.equal(featureNames(inmem), featureNames(ondisk)))) \r\n        return(\"Object have different feature names.\")\r\n    ## access data on disk only once\r\n    spondisk <- spectra(ondisk)\r\n    for (i in seq_len(l)) {\r\n        if (!isTRUE(speq <- all.equal(spondisk[[i]], inmem[[i]]))) \r\n            return(\"Spectra at position\", i, \"are different.\")\r\n    }\r\n    return(TRUE)\r\n}\r\n```\r\n\r\nis faster as it first checks the lengths and doesn't bother proceeding if different, then checks the feature names, and stops as soon as one spectrum is different. `all.equal(spectra(x), spectra(y))` would compare all along. In addition, and that's probably more important, is that the messages are clearer than comparing the spectra lists, which will, for example, print \r\n\r\n```r\r\n> all.equal(spectra(x)[1:4], spectra(x)[3:10])\r\n [1] \"Names: 4 string mismatches\"                                                                      \r\n [2] \"Length mismatch: comparison on first 4 components\"                                               \r\n [3] \"Component 1: Attributes: < Component “acquisitionNum”: Mean relative difference: 0.001992032 >\"  \r\n [4] \"Component 1: Attributes: < Component “intensity”: Numeric: lengths (211, 234) differ >\"          \r\n [5] \"Component 1: Attributes: < Component “mz”: Numeric: lengths (211, 234) differ >\"                 \r\n [6] \"Component 1: Attributes: < Component “peaksCount”: Mean relative difference: 0.1090047 >\"        \r\n [7] \"Component 1: Attributes: < Component “precursorIntensity”: Mean relative difference: 0.5372487 >\"\r\n [8] \"Component 1: Attributes: < Component “precursorMz”: Mean relative difference: 0.272425 >\"        \r\n [9] \"Component 1: Attributes: < Component “rt”: Mean relative difference: 0.000944806 >\"              \r\n[10] \"Component 1: Attributes: < Component “scanIndex”: Mean relative difference: 1 >\"                 \r\n[11] \"Component 1: Attributes: < Component “tic”: Mean relative difference: 0.3599503 >\"               \r\n[12] \"Component 2: Attributes: < Component “acquisitionNum”: Mean relative difference: 0.00199005 >\"   \r\n[13] \"Component 2: Attributes: < Component “intensity”: Numeric: lengths (124, 215) differ >\"          \r\n[14] \"Component 2: Attributes: < Component “mz”: Numeric: lengths (124, 215) differ >\"                 \r\n[15] \"Component 2: Attributes: < Component “peaksCount”: Mean relative difference: 0.733871 >\"         \r\n[16] \"Component 2: Attributes: < Component “precursorCharge”: Mean relative difference: 0.5 >\"         \r\n[17] \"Component 2: Attributes: < Component “precursorIntensity”: Mean relative difference: 0.4156109 >\"\r\n[18] \"Component 2: Attributes: < Component “precursorMz”: Mean relative difference: 0.1041751 >\"       \r\n[19] \"Component 2: Attributes: < Component “rt”: Mean relative difference: 0.0006463667 >\"             \r\n[20] \"Component 2: Attributes: < Component “scanIndex”: Mean relative difference: 0.6666667 >\"         \r\n[21] \"Component 2: Attributes: < Component “tic”: Mean relative difference: 0.08263207 >\"              \r\n[22] \"Component 3: Attributes: < Component “acquisitionNum”: Mean relative difference: 0.001988072 >\"  \r\n[23] \"Component 3: Attributes: < Component “intensity”: Numeric: lengths (234, 156) differ >\"          \r\n[24] \"Component 3: Attributes: < Component “mz”: Numeric: lengths (234, 156) differ >\"                 \r\n[25] \"Component 3: Attributes: < Component “peaksCount”: Mean relative difference: 0.3333333 >\"        \r\n[26] \"Component 3: Attributes: < Component “precursorIntensity”: Mean relative difference: 0.2217871 >\"\r\n[27] \"Component 3: Attributes: < Component “precursorMz”: Mean relative difference: 0.3542217 >\"       \r\n[28] \"Component 3: Attributes: < Component “rt”: Mean relative difference: 0.0006376849 >\"             \r\n[29] \"Component 3: Attributes: < Component “scanIndex”: Mean relative difference: 0.5 >\"               \r\n[30] \"Component 3: Attributes: < Component “tic”: Mean relative difference: 0.5627042 >\"               \r\n[31] \"Component 4: Attributes: < Component “acquisitionNum”: Mean relative difference: 0.001986097 >\"  \r\n[32] \"Component 4: Attributes: < Component “intensity”: Numeric: lengths (215, 63) differ >\"           \r\n[33] \"Component 4: Attributes: < Component “mz”: Numeric: lengths (215, 63) differ >\"                  \r\n[34] \"Component 4: Attributes: < Component “peaksCount”: Mean relative difference: 0.7069767 >\"        \r\n[35] \"Component 4: Attributes: < Component “precursorCharge”: Mean relative difference: 0.3333333 >\"   \r\n[36] \"Component 4: Attributes: < Component “precursorIntensity”: Mean relative difference: 0.2813519 >\"\r\n[37] \"Component 4: Attributes: < Component “precursorMz”: Mean relative difference: 0.3669057 >\"       \r\n[38] \"Component 4: Attributes: < Component “rt”: Mean relative difference: 0.0006916124 >\"             \r\n[39] \"Component 4: Attributes: < Component “scanIndex”: Mean relative difference: 0.4 >\"               \r\n[40] \"Component 4: Attributes: < Component “tic”: Mean relative difference: 0.8290652 >\"  \r\n```\r\nwhen really, the most important information is that the lengths are different. "}}
{"actor":{"display_login":"lgatto"}}