Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1,drop=TRUE] no longer returns vector from FLQuant. #43

Closed
colinpmillar opened this issue Sep 30, 2017 · 3 comments
Closed

[1,drop=TRUE] no longer returns vector from FLQuant. #43

colinpmillar opened this issue Sep 30, 2017 · 3 comments

Comments

@colinpmillar
Copy link
Member

colinpmillar commented Sep 30, 2017

Change in behaviour occurs in commit: 6704455

Starting with a simple 2D quant:

    library(FLCore)
    ## FLCore (Version 2.6.3.9005, packaged: Sat Sep 30 02:06:33 2017)

    (x <- FLQuant(as.numeric(paste0(rep(1:2, 9), 
                                    rep(1:9, each = 2))), dim = c(2, 9)))
    ## An object of class "FLQuant"
    ## , , unit = unique, season = all, area = unique
    ## 
    ##      year
    ## quant 1  2  3  4  5  6  7  8  9 
    ##     1 11 12 13 14 15 16 17 18 19
    ##     2 21 22 23 24 25 26 27 28 29
    ## 
    ## units:  NA

commit: 26fc70c

    install_github("flr/flcore@26fc70ceceb1608a44440c8f4688e822fe8e731d")
    ## Reloading installed FLCore
    ## FLCore (Version 2.6.3.9005, packaged: Sat Sep 30 02:07:00 2017)

    # up till now the following are and have been equivalent
    x@.Data[1:2,,,,,, drop=TRUE]
    ##      year
    ## quant  1  2  3  4  5  6  7  8  9
    ##     1 11 12 13 14 15 16 17 18 19
    ##     2 21 22 23 24 25 26 27 28 29

    x[1:2,,,,,, drop=TRUE]
    ##      year
    ## quant  1  2  3  4  5  6  7  8  9
    ##     1 11 12 13 14 15 16 17 18 19
    ##     2 21 22 23 24 25 26 27 28 29

    x[1:2, drop=TRUE]
    ##      year
    ## quant  1  2  3  4  5  6  7  8  9
    ##     1 11 12 13 14 15 16 17 18 19
    ##     2 21 22 23 24 25 26 27 28 29

following commit: 6704455

    install_github("flr/flcore@6704455aa29390c834310572c165025341be3231")
    ## Reloading installed FLCore
    ## FLCore (Version 2.6.3.9005, packaged: Sat Sep 30 02:07:25 2017)

    # after this commit the following are no longer equivalent
    x@.Data[1:2,,,,,, drop=TRUE]
    ##      year
    ## quant  1  2  3  4  5  6  7  8  9
    ##     1 11 12 13 14 15 16 17 18 19
    ##     2 21 22 23 24 25 26 27 28 29

    x[1:2,,,,,, drop=TRUE]
    ## [1] 11 21

    x[1:2, drop=TRUE]
    ## [1] 11 21
@colinpmillar colinpmillar changed the title [1,drop=TRUE] no longer returns vector from FLQuant [1,drop=TRUE] no longer returns vector from FLQuant. Occurs in 6704455aa29390c834310572c165025341be3231 Sep 30, 2017
@colinpmillar colinpmillar changed the title [1,drop=TRUE] no longer returns vector from FLQuant. Occurs in 6704455aa29390c834310572c165025341be3231 [1,drop=TRUE] no longer returns vector from FLQuant. Sep 30, 2017
@iagomosqueira
Copy link
Member

I see where the problem comes from. From that commit if a single vector of is given, and drop=TRUE, it is taken to be used to select elements along the whole object, for example

x[c(1,4,7,8), drop=TRUE]
[1] 11 22 14 24

The code doing it is at, https://github.com/flr/FLCore/blob/master/R/FLArray.R#L159

This is trying to mimic the behaviour of the array class, where you an do

x@.Data[c(1,2,4,5)]
[1] 11 21 22 13

which could not be done in FLQuant.

The confusion only occurs when sub-setting on the first dimension, not on others

x[,1:2, drop=TRUE]
     year
quant  1  2
    1 11 12
    2 21 22

Now, I would like to preserve this new behaviour, as it got added because it was needed, but would also like to find a way for your subsetting needs to work.

Are you trying to select some rows and also convert to an array with less dimensions?

@colinpmillar
Copy link
Member Author

I was actually using what ever worked, so probably not a bug at all :)
The behaviour you have now, is what you get with array, so I am quite happy with that - it was more to make you aware that there was a change is how the [] function behaved.
Happy for this to be closed as an isssue

@iagomosqueira
Copy link
Member

OK, if you find it too difficult to extract elements from an FLQuant into a plain array let me know and we look at it again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants