All Projects → eddelbuettel → rcppcnpy

eddelbuettel / rcppcnpy

Licence: GPL-2.0 license
Rcpp bindings for NumPy files

Programming Languages

C++
36643 projects - #6 most used programming language
r
7636 projects
TeX
3793 projects
python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to rcppcnpy

packagefinder
Comfortable search for R packages on CRAN, either directly from the R console or with an R Studio add-in
Stars: ✭ 43 (+79.17%)
Mutual labels:  cran, r-package
Pacman
A package management tools for R
Stars: ✭ 220 (+816.67%)
Mutual labels:  cran, r-package
Webservices
CRAN WebTechnologies Task View
Stars: ✭ 160 (+566.67%)
Mutual labels:  cran, r-package
Rblpapi
R package interfacing the Bloomberg API from https://www.bloomberglabs.com/api/
Stars: ✭ 133 (+454.17%)
Mutual labels:  cran, r-package
healthyR
Hospital Data Analysis Workflow Tools
Stars: ✭ 21 (-12.5%)
Mutual labels:  cran, r-package
Pinp
Pinp Is Not PNAS -- Two-Column PDF Template
Stars: ✭ 134 (+458.33%)
Mutual labels:  cran, r-package
Arsenal
An Arsenal of 'R' Functions for Large-Scale Statistical Summaries
Stars: ✭ 171 (+612.5%)
Mutual labels:  cran, r-package
Rinside
Seamless embedding of R in C++ programs
Stars: ✭ 112 (+366.67%)
Mutual labels:  cran, r-package
oem
Penalized least squares estimation using the Orthogonalizing EM (OEM) algorithm
Stars: ✭ 22 (-8.33%)
Mutual labels:  cran, r-package
Littler
A scripting and command-line front-end for GNU R
Stars: ✭ 238 (+891.67%)
Mutual labels:  cran, r-package
Drat
Drat R Archive Template
Stars: ✭ 127 (+429.17%)
Mutual labels:  cran, r-package
rcppsimdjson
Rcpp Bindings for the 'simdjson' Header Library
Stars: ✭ 103 (+329.17%)
Mutual labels:  cran, r-package
Minicran
R package to create internally consistent, mini version of CRAN
Stars: ✭ 123 (+412.5%)
Mutual labels:  cran, r-package
Osrm
Shortest Paths and Travel Time from OpenStreetMap with R
Stars: ✭ 160 (+566.67%)
Mutual labels:  cran, r-package
Mlr
Machine Learning in R
Stars: ✭ 1,542 (+6325%)
Mutual labels:  cran, r-package
Simmer
Discrete-Event Simulation for R
Stars: ✭ 170 (+608.33%)
Mutual labels:  cran, r-package
Markovchain
Easy Handling Discrete Time Markov Chains
Stars: ✭ 80 (+233.33%)
Mutual labels:  cran, r-package
Wooldridge
The official R data package for "Introductory Econometrics: A Modern Approach". A vignette contains example models from each chapter.
Stars: ✭ 90 (+275%)
Mutual labels:  cran, r-package
Tint
Tint is not Tufte
Stars: ✭ 226 (+841.67%)
Mutual labels:  cran, r-package
rdomains
Classifying the content of domains
Stars: ✭ 47 (+95.83%)
Mutual labels:  cran, r-package

RcppCNPy: Rcpp bindings for NumPy files

CI License CRAN Dependencies Downloads Last Commit
status DOI

About

This package uses the cnpy library written by Carl Rogers to provide read and write facilities for files created with (or for) the NumPy extension for Python. Vectors and matrices of numeric types can be read or written to and from files as well as compressed files. Support for integer files is available if the package has been built with -std=c++11 which is the default starting with release 0.2.3 following the release of R 3.1.0, and available on all platforms following the release of R 3.3.0 with the updated 'Rtools'.

Example

The following Python code

>>> import numpy as np
>>> fm = np.arange(12).reshape(3,4) * 1.1
>>> fm
array([[  0. ,   1.1,   2.2,   3.3],
       [  4.4,   5.5,   6.6,   7.7],
       [  8.8,   9.9,  11. ,  12.1]])
>>> np.save("fmat.npy", fm)
>>> 
>>> im = np.arange(12).reshape(3,4)
>>> im
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11]])
>>> np.save("imat.npy", im)
>>> 

saves two matrices in floating-point and integer representation.

With this R code we can read and assign the files:

R> library(RcppCNPy)
R> fmat <- npyLoad("fmat.npy")
R> fmat
     [,1] [,2] [,3] [,4]
[1,]  0.0  1.1  2.2  3.3
[2,]  4.4  5.5  6.6  7.7
[3,]  8.8  9.9 11.0 12.1
R> 
R> imat <- npyLoad("imat.npy", "integer")
R> imat
     [,1] [,2] [,3] [,4]
[1,]    0    1    2    3
[2,]    4    5    6    7
[3,]    8    9   10   11
R> 

Going the opposite way by saving in R and reading in Python works equally well. An extension not present in CNPy allows reading and writing of gzip-compressed files.

The package has been tested and used on several architecture, and copes correctly with little-vs-big endian switches.

More details are available in the package vignette.

Installation

The package is on CRAN and can be installed per:

R> install.packages("RcppCNPy")

Status

On CRAN, stable and mostly feature-complete.

Alternative: reticulate

The reticulate package can also provide easy and comprehensive access to NumPy data; see the additional vignette in RcppCNPy for examples and more details.

Feedback

Contributions are welcome, please use the GitHub issue tracker for bug reports, feature requests or general discussions before sending pull requests.

Author

Dirk Eddelbuettel and Wush Wu

License

GPL (>= 2)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].