{"action":"created","issue":{"url":"https://api.github.com/repos/dankelley/oce/issues/1395","repository_url":"https://api.github.com/repos/dankelley/oce","labels_url":"https://api.github.com/repos/dankelley/oce/issues/1395/labels{/name}","comments_url":"https://api.github.com/repos/dankelley/oce/issues/1395/comments","events_url":"https://api.github.com/repos/dankelley/oce/issues/1395/events","html_url":"https://github.com/dankelley/oce/issues/1395","id":312549360,"number":1395,"title":"request: concatenate() for oce objects","user":{"login":"dankelley","id":99469,"avatar_url":"https://avatars1.githubusercontent.com/u/99469?v=4","gravatar_id":"","url":"https://api.github.com/users/dankelley","html_url":"https://github.com/dankelley","followers_url":"https://api.github.com/users/dankelley/followers","following_url":"https://api.github.com/users/dankelley/following{/other_user}","gists_url":"https://api.github.com/users/dankelley/gists{/gist_id}","starred_url":"https://api.github.com/users/dankelley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dankelley/subscriptions","organizations_url":"https://api.github.com/users/dankelley/orgs","repos_url":"https://api.github.com/users/dankelley/repos","events_url":"https://api.github.com/users/dankelley/events{/privacy}","received_events_url":"https://api.github.com/users/dankelley/received_events","type":"User","site_admin":false},"labels":[{"id":174389560,"url":"https://api.github.com/repos/dankelley/oce/labels/development","name":"development","color":"bfd4f2","default":false},{"id":27728,"url":"https://api.github.com/repos/dankelley/oce/labels/request","name":"request","color":"bfe5bf","default":false}],"state":"open","locked":false,"assignee":{"login":"dankelley","id":99469,"avatar_url":"https://avatars1.githubusercontent.com/u/99469?v=4","gravatar_id":"","url":"https://api.github.com/users/dankelley","html_url":"https://github.com/dankelley","followers_url":"https://api.github.com/users/dankelley/followers","following_url":"https://api.github.com/users/dankelley/following{/other_user}","gists_url":"https://api.github.com/users/dankelley/gists{/gist_id}","starred_url":"https://api.github.com/users/dankelley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dankelley/subscriptions","organizations_url":"https://api.github.com/users/dankelley/orgs","repos_url":"https://api.github.com/users/dankelley/repos","events_url":"https://api.github.com/users/dankelley/events{/privacy}","received_events_url":"https://api.github.com/users/dankelley/received_events","type":"User","site_admin":false},"assignees":[{"login":"dankelley","id":99469,"avatar_url":"https://avatars1.githubusercontent.com/u/99469?v=4","gravatar_id":"","url":"https://api.github.com/users/dankelley","html_url":"https://github.com/dankelley","followers_url":"https://api.github.com/users/dankelley/followers","following_url":"https://api.github.com/users/dankelley/following{/other_user}","gists_url":"https://api.github.com/users/dankelley/gists{/gist_id}","starred_url":"https://api.github.com/users/dankelley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dankelley/subscriptions","organizations_url":"https://api.github.com/users/dankelley/orgs","repos_url":"https://api.github.com/users/dankelley/repos","events_url":"https://api.github.com/users/dankelley/events{/privacy}","received_events_url":"https://api.github.com/users/dankelley/received_events","type":"User","site_admin":false}],"milestone":null,"comments":0,"created_at":"2018-04-09T14:17:04Z","updated_at":"2018-04-09T20:00:02Z","closed_at":null,"author_association":"OWNER","body":"As mentioned in #1394, I've been fiddling with a function to concatenate oce objects. This could be useful in e.g. stringing together the one-month data files that env-canada produces (that's the example in #1394, actually). Other use cases can come to mind.\r\n\r\nMy provisional code is as below, just to show that this is about halfway done already.  (Docs are 1/4 of the work of any such addition, partly because they require extra thought on functionality, e.g. what should be the metadata for the returned object).\r\n\r\nIf other devels think this is worth doing, I'll fiddle with it in the \"dk\" branch. I have lots of time to get it working right (or to drop the idea) for my usual sat-morning merge of dk into develop.\r\n```R\r\nlibrary(dc)\r\nlibrary(oce)\r\n\r\nconcatenate <- function(...)\r\n{\r\n    dots <- list(...)\r\n    ndots <- length(dots)\r\n    if (length(dots) < 2) stop(\"give 2 or more objects\")\r\n    n1 <- sort(names(dots[[1]]@data))\r\n    res <- dots[[1]]\r\n    f1 <- sort(names(dots[[1]]@metadata$flags))\r\n    for (i in 2:ndots) {\r\n        ni <- sort(names(dots[[i]]@data))\r\n        if (!identical(n1, ni))\r\n            stop(\"data name mismatch between object 1 (\",\r\n                 paste(n1, collapse=\" \"), \") and object \", i,\r\n                 \"(\", paste(ni, collapse=\" \"), \")\")\r\n        for (n in ni) {\r\n            res@data[[n]] <- c(res@data[[n]], dots[[i]]@data[[n]])\r\n        }\r\n        if (!is.null(f1)) {\r\n            fi <- sort(names(dots[[1]]@metadata$flags))\r\n            if (!identical(f1, fi))\r\n                stop(\"flag mismatch between object 1 (\",\r\n                     paste(f1, collapse=\" \"), \") and object \", i,\r\n                     \"(\", paste(fi, collapse=\" \"), \")\")\r\n            for (f in fi) {\r\n                res@metadata$flags[[f]] <- c(res@metadata$flags[[f]], dots[[i]]@metadata$flags[[f]])\r\n            }\r\n        }\r\n    }\r\n    res\r\n}\r\n\r\nf8 <- dc.met(6358, 2003, 8)\r\nf9 <- dc.met(6358, 2003, 9)\r\nd8 <- read.met(f8)\r\nd9 <- read.met(f9)\r\n\r\nd89 <- concatenate(d8, d9)\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/dankelley/oce/issues/comments/379875507","html_url":"https://github.com/dankelley/oce/issues/1395#issuecomment-379875507","issue_url":"https://api.github.com/repos/dankelley/oce/issues/1395","id":379875507,"user":{"login":"dankelley","id":99469,"avatar_url":"https://avatars1.githubusercontent.com/u/99469?v=4","gravatar_id":"","url":"https://api.github.com/users/dankelley","html_url":"https://github.com/dankelley","followers_url":"https://api.github.com/users/dankelley/followers","following_url":"https://api.github.com/users/dankelley/following{/other_user}","gists_url":"https://api.github.com/users/dankelley/gists{/gist_id}","starred_url":"https://api.github.com/users/dankelley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dankelley/subscriptions","organizations_url":"https://api.github.com/users/dankelley/orgs","repos_url":"https://api.github.com/users/dankelley/repos","events_url":"https://api.github.com/users/dankelley/events{/privacy}","received_events_url":"https://api.github.com/users/dankelley/received_events","type":"User","site_admin":false},"created_at":"2018-04-09T20:00:02Z","updated_at":"2018-04-09T20:00:02Z","author_association":"OWNER","body":"I added this to the \"dk\" branch. It was a lot trickier than the sample code given above, because a lot of data items are not vectors, so `c()` won't work. For matrices I now use `rbind()`, and for 3D arrays I use `rbind()` in a loop that runs through the third dimension.\r\n\r\nThere is a fair bit of fiddly work, because of what I consider some poor decisions of object layout. For example, the `adp` class has an item named `numberOfSamples` in its `metadata` slot, and (presently) `plot,adp-method` uses that information, instead of looking at the first element returned by e.g. `dim(adp[[\"v\"]])`. Therefore, `concatenate()` has to set a value for `@metadata$numberOfSamples` after doing the concatenation. Of course, this is not difficult, but it's fiddly. I think other objects will have similar problems -- e.g. `argo` objects for individual profiles may require setting work.\r\n\r\nSo far, `concatenate()` is documented to only work for `met` and `adp` objects. I will update  the docs as I add new things.  Those docs ask users to report issues, and I intend to rely on that, once I finish up with a few objects where I think this function will be most helpful."}}
{"actor":{"display_login":"dankelley"}}