Skip to content

Commit

Permalink
Merge pull request #118 from srz-zumix/feature/support_statement_r
Browse files Browse the repository at this point in the history
support R statement
  • Loading branch information
srz-zumix authored Aug 3, 2022
2 parents ec8661c + f61abaa commit c72eb09
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion samples/command/src/r/sample.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ summary(fit) ## summary

cat("All done\n")

source("test1.R")
source("test1.R"); source("test2.R")

test1()
test2()

# R language references:
# https://cran.r-project.org/manuals.html
3 changes: 3 additions & 0 deletions samples/command/src/r/test2.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test2 <- function() {
print("Test2")
}
13 changes: 8 additions & 5 deletions wandbox/__r__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

from .cli import CLI
from .runner import Runner
from .utils import split_statements


class RscriptRunner(Runner):

SOURCE_REGEX = re.compile(r'^\s*source\s*\((.*?)\)\s*$')
SOURCE_REGEX = re.compile(r'^\s*source\s*\((.*?)\)\s*(;|)\s*$')

def reset(self):
self.sourced = []
Expand All @@ -16,10 +17,12 @@ def make_code(self, file, filepath, filename):
files = dict()
code = ''
for line in file:
m = self.SOURCE_REGEX.match(line)
if m:
module = m.group(1).strip('(\'")')
files.update(self.source(os.path.dirname(filepath), module.strip()))
statements = split_statements(line, commenters="#")
for statement in statements:
m = self.SOURCE_REGEX.match(statement)
if m:
module = m.group(1).strip('(\'")')
files.update(self.source(os.path.dirname(filepath), module.strip()))
code += line
files[filename] = code
return files
Expand Down

0 comments on commit c72eb09

Please sign in to comment.