<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
A Python script that uses numpy and pyper.
"""
from __future__ import division, print_function

import os
import numpy as np
import pyper
import sys

# additional search paths
Rpaths = list()
# win
Rroot_win = "C:\\Program Files\\R"
if os.path.exists(Rroot_win):
    for append in ["", "\\bin\\i386"]:
        # This will work independent of the installed R version
        Rpaths += [ os.path.join(Rroot_win, d+append) for d in os.listdir(Rroot_win) ]
        # win frozen
        if hasattr(sys, "frozen"):
            Rroot_win_frozen = os.path.join(os.path.abspath(sys._MEIPASS), "R")
            if os.path.exists(Rroot_win_frozen):
                Rpaths += [  os.path.join(Rroot_win_frozen, d+append) for d in os.listdir(Rroot_win_frozen) ]
# linux
Rpaths += ["/usr/bin"]

print(Rpaths)

Rexes = list()
for binary in ["R", "R.exe"]:
    Rexes += [ os.path.join(loc, binary) for loc in Rpaths ]

# standard path search:
Rexe = "R"

# find other installation:
for b in Rexes:
    if os.path.exists(b):
        Rexe = b
        break
print("Using R: ", Rexe)

#Open a pyper instance
r1 = pyper.R(use_pandas=True, RCMD=Rexe) 
# Perform a simple computation
xs = np.linspace(0,1,10)
r1.assign("xs", xs) 
r1("DFRAME=data.frame(xs)")
r1("result <- DFRAME[xs]*2")   
# Retrieve the result
result = r1.get("result")
try:
    # R 3.0.4 linux
    data = result.as_matrix().reshape(-1)
except AttributeError:
    # `result` is already an ndarray?
    # R 3.2.2 windows
    data = np.array(result, dtype=float).reshape(-1)

# Validate the result<commit_msg>update R paths<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
A Python script that uses numpy and pyper.
"""
from __future__ import division, print_function

import os
import numpy as np
import pyper
import sys

# additional search paths
Rpaths = list()
# win
Rroot_win = "C:\\Program Files\\R"
if os.path.exists(Rroot_win):
    for append in ["", "\\bin\\i386"]:
        # This will work independent of the installed R version
        Rpaths += [ os.path.join(Rroot_win, d+append) for d in os.listdir(Rroot_win) ]
# win frozen
if hasattr(sys, "frozen"):
    Rroot_win_frozen = os.path.join(os.path.abspath(sys._MEIPASS), "R")
    if os.path.exists(Rroot_win_frozen):
        Rpaths += [  os.path.join(Rroot_win_frozen, d+append) for d in os.listdir(Rroot_win_frozen) ]
# linux
Rpaths += ["/usr/bin"]

Rexes = list()
for binary in ["R", "R.exe"]:
    Rexes += [ os.path.join(loc, binary) for loc in Rpaths ]

Rexe_avail = [ r for r in Rexes if os.path.exists(r) ]

print(Rexe_avail)


# standard path search:
if len(Rexe_avail) == 0:
    Rexe = "R"
else:
    Rexe = Rexe_avail[0]

# find other installation:

print("Using R: ", Rexe)

#Open a pyper instance
r1 = pyper.R(use_pandas=True, RCMD=Rexe) 
# Perform a simple computation
xs = np.linspace(0,1,10)
r1.assign("xs", xs) 
r1("DFRAME=data.frame(xs)")
r1("result <- DFRAME[xs]*2")   
# Retrieve the result
result = r1.get("result")
try:
    # R 3.0.4 linux
    data = result.as_matrix().reshape(-1)
except AttributeError:
    # `result` is already an ndarray?
    # R 3.2.2 windows
    data = np.array(result, dtype=float).reshape(-1)

# Validate the result
{'fraction_non_alphanumeric': 0.14774830351634793, 'fraction_numerical': 0.01418877236273905, 'mean_word_length': 3.388362652232747, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1951035', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1218, 'n_words': 322}