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

Problems using filemode = "rb" #2

Closed
PeteHaitch opened this issue Jun 16, 2017 · 3 comments
Closed

Problems using filemode = "rb" #2

PeteHaitch opened this issue Jun 16, 2017 · 3 comments

Comments

@PeteHaitch
Copy link

Hi Kylie,

I've just started exploring matter, it looks really cool! I hit an issue trying to specify filemode = "rb" when creating a matter matrix. Am I doing something wrong?

Thanks

library(matter)
#> Loading required package: biglm
#> Loading required package: DBI
#> 
#> Attaching package: 'matter'
#> The following objects are masked from 'package:base':
#> 
#>     apply, scale

# Using the default filemode = "rb+" works fine
x <- matter_mat(1:100, nrow=10, ncol=10)
x
#> An object of class 'matter_matc'
#>   <10 row, 10 column> on-disk matrix
#>     sources: 1 
#>     datamode: numeric 
#>     12.1 KB in-memory
#>     800 bytes on-disk

# Specifying filemode = "rb" causes R to hang (killed after 30 seconds)
x <- matter_mat(1:100, nrow=10, ncol=10, filemode = "rb")

sessionInfo()
#>R version 3.4.0 (2017-04-21)
#>Platform: x86_64-apple-darwin15.6.0 (64-bit)
#>Running under: macOS Sierra 10.12.5
#>
#>Matrix products: default
#>BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
#>LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
#>
#>locale:
#>[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
#>
#>attached base packages:
#>[1] stats     graphics  grDevices utils     datasets  methods   base
#>
#>other attached packages:
#>[1] matter_1.3.3 biglm_0.9-1  DBI_0.6-1

#>loaded via a namespace (and not attached):
#>[1] compiler_3.4.0      Matrix_1.2-10       parallel_3.4.0
#>[4] grid_3.4.0          BiocGenerics_0.23.0 irlba_2.2.1
#>[7] lattice_0.20-35
@kuwisdelu
Copy link
Owner

Hi Pete,

Using "rb" makes it read-only, so it expects that the matrix already exists in a file on disk. As a result, when it tries to create and assign initial values, it cannot write to the file (since it's opened as read-only).

Hanging is bad, so this should probably either throw an error if no existing file is given, or it should temporarily open the file as read/write for the initialization.

-Kylie

@PeteHaitch
Copy link
Author

Oh, that makes sense! I thought "rb" was to create a read-only file rather than to read from a read-only file. What is the recommended way to create a file but then make it read-only for subsequent use?
Thanks,
Pete

@kuwisdelu
Copy link
Owner

Create it using filemode="rb+" (default) then do:

filemode(x) <- "rb"

-Kylie

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