Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,44 @@

.onLoad <- function( libname, pkgname ){

if (.Platform$OS.type == 'windows') {
rpyopts <- getOption('rPython.paths')
rarch <- .Platform$r_arch # i386 or x64

if (rarch %in% names(rpyopts)) {
wrongarch <- setdiff(c('i386', 'x64'), rarch)[[1]]

pyhome <- rpyopts[[rarch]]
pypath <- file.path(pyhome, 'Lib')
pyhomewin <- normalizePath(pyhome)
pypathwin <- normalizePath(pypath)

wrongpyhome <- rpyopts[[wrongarch]]
wrongpyhomewin <- normalizePath(wrongpyhome)

if (! nzchar(Sys.getenv("PYTHONHOME"))) {
message("Manually setting PYTHONHOME: ", pyhome)
Sys.setenv(PYTHONHOME = pyhomewin)
}
if (! nzchar(Sys.getenv("PYTHONPATH"))) {
message("Manually setting PYTHONPATH: ", pypath)
Sys.setenv(PYTHONPATH = pypathwin)
}

path <- strsplit(Sys.getenv("PATH"), ";")[[1]]
idx <- tolower(wrongpyhomewin) ==
tolower(substr(path, 1, nchar(wrongpyhomewin)))
path[idx] <- paste(pyhomewin, substr(path[idx], 1 + nchar(wrongpyhomewin), 999), sep = "")
Sys.setenv(PATH = paste(path, collapse = ";"))
} else {
# provide a warning to the user suggesting adding an option
warning(paste("Did not find definitions of the paths to 32-bit and 64-bit python.",
"Suggestion: adding the following to your .Rprofile file:",
"options(rPython.paths = list(i386 = '/path/to/py32', x64 = '/path/to/py64'))",
collapse = "\n"))
}
}

library.dynam( "rPython", pkgname, libname )
.C( "py_init", PACKAGE = "rPython" )
}
Expand Down
30 changes: 12 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@ This is rPython for Windows. If you are on Linux/Mac, you can [install it from C
## Installation

* Install [Rtools](http://cran.r-project.org/bin/windows/Rtools/)
* Install [devtools](http://cran.r-project.org/web/packages/devtools/index.html) by running
```
install.packages("devtools")
library(devtools)
```
* Download the package as a zip file (see "Download Zip" button to the right of this page).
* Unzip the package and rename the directory as `rPython` (not `rPython-win`).
* If needed, edit the `configure.win` file inside the directory. By default, it contains the lines

```
echo 'PKG_LIBS=-LC:/python27/libs -lpython27' > src/makevars.win
echo 'PKG_CFLAGS=-I"C:/Python27/include"' >> src/makevars.win
```

and you should edit them to point to the path where you installed Python. In the default configuration it is assumed that the Python version is 2.7 and that it is installed in `C:/Python27`. Change it according to your Python installation.
* Install the package running `install("path/to/rPython")`. For instance, I run
```
install("C:/Users/carlos/Downloads/rPython")
```
* (Previous versions of this package contained `configure.*` files; these are not longer necessary and have been removed.)
* As needed, edit the `src/makevars.win` file to identify the python path(s). The default assumes that 32-bit python is installed within `C:\Python27\i386`, and the 64-bit python is installed within `C:\Python27\x64`, with relatively identical sub-directory hierarchies.

* Add the following to your `$HOME/.Rprofile` file:

```r
options(rPython.paths = list(i386 = "/Python27/i386", x64 = "/Python27/x64"))
```

This option is required to properly distinguish between 32-bit and 64-bit pythons (both for compilation and every time you load rPython). These instructions have not been tested on a system with only one version of python available ...

* The package must be compiled on the command-line (`devtools` will not currently work). `R CMD INSTALL /path/to/rPython` (or `R CMD INSTALL .` if in the current directory). You may use `R CMD INSTALL --build .` if you want to create a binary package for storage or distribution.

## Issues

Expand Down
7 changes: 3 additions & 4 deletions cleanup
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/sh

rm src/pycall.o
rm src/rPython.so
rm srcc/symbols.rds
rm config.log
rm config.status
rm src/rPython.so src/rPython.dll
rm src/symbols.rds
rm -rf src-i386/ src-x64/
Loading