<commit_before>#-*- conding: utf-8 -*-

import os
import warnings
import logging

logger = logging.getLogger('RMD_READER')

from pelican import readers
from pelican import signals
from pelican import settings

knitr = None
rmd = False
fig_path = None

def initsignal(pelicanobj):
    global knitr, rmd, fig_path, robjects
    try:
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            from rpy2.robjects.packages import importr
            import rpy2.robjects as robjects
        knitr = importr('knitr')
        idx = knitr.opts_knit.names.index('set')
        PATH = pelicanobj.settings.get('PATH','%s/content' % settings.DEFAULT_CONFIG.get('PATH'))
        logger.debug("RMD_READER PATH = %s", PATH)
        knitr.opts_knit[idx](**{'base.dir': PATH})
        knitroptsknit = pelicanobj.settings.get('RMD_READER_KNITR_OPTS_KNIT', None)
        if knitroptsknit:
            knitr.opts_knit[idx](**{str(k): v for k,v in knitroptsknit.items()})
        idx = knitr.opts_chunk.names.index('set')
        knitroptschunk = pelicanobj.settings.get('RMD_READER_KNITR_OPTS_CHUNK', None)
        if knitroptschunk:
            fig_path = knitroptschunk['fig.path'] if 'fig.path' in knitroptschunk else 'figure/'
            knitr.opts_chunk[idx](**{str(k): v for k,v in knitroptschunk.items()})
        rmd = True
    except ImportError as ex:
        rmd = False

class RmdReader(readers.BaseReader):
    file_extensions = ['Rmd', 'rmd']<commit_msg>Set R's init options<commit_after>#-*- conding: utf-8 -*-

import os
import warnings
import logging

logger = logging.getLogger('RMD_READER')

from pelican import readers
from pelican import signals
from pelican import settings

knitr = None
rmd = False
fig_path = None

def initsignal(pelicanobj):
    global knitr, rmd, fig_path, robjects
    try:
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            import rpy2.rinterface
            rpy2.rinterface.set_initoptions((b'rpy2', b'--no-save', b'--vanilla', b'--quiet'))
            from rpy2.robjects.packages import importr
            import rpy2.robjects as robjects
        knitr = importr('knitr')
        idx = knitr.opts_knit.names.index('set')
        PATH = pelicanobj.settings.get('PATH','%s/content' % settings.DEFAULT_CONFIG.get('PATH'))
        logger.debug("RMD_READER PATH = %s", PATH)
        knitr.opts_knit[idx](**{'base.dir': PATH})
        knitroptsknit = pelicanobj.settings.get('RMD_READER_KNITR_OPTS_KNIT', None)
        if knitroptsknit:
            knitr.opts_knit[idx](**{str(k): v for k,v in knitroptsknit.items()})
        idx = knitr.opts_chunk.names.index('set')
        knitroptschunk = pelicanobj.settings.get('RMD_READER_KNITR_OPTS_CHUNK', None)
        if knitroptschunk:
            fig_path = knitroptschunk['fig.path'] if 'fig.path' in knitroptschunk else 'figure/'
            knitr.opts_chunk[idx](**{str(k): v for k,v in knitroptschunk.items()})
        rmd = True
    except ImportError as ex:
        rmd = False

class RmdReader(readers.BaseReader):
    file_extensions = ['Rmd', 'rmd']
{'fraction_non_alphanumeric': 0.12286908973946607, 'fraction_numerical': 0.002894821486008363, 'mean_word_length': 3.1029023746701845, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4117304', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1073, 'n_words': 220}