PaulHurleyuk
PaulHurleyuk

Reputation: 8169

Assign output of RScript to makefile variable

I'm trying to automate some R analysis using a makefile. The analysis is a monthly data analysis and report. It's working well so far, but to expand it I'd like to have the default action to be to create the current report, but be able to specifiy a month if required.

I'm having trouble assigning the default report period (calculated by an R script) to a makefile variable.

Makefile

# Assign a data identifier. 
#IRL could use R to assign current if not specified as an arg to make
month :=     $(Rscript './R/reportperiod.R')

test:
    echo $(month)

and the reportperiod.R script is

require(lubridate)

cat(format(floor_date(as.POSIXct(Sys.time())-10*24*60*60, unit="month"), format="%Y%b"))

but this just displays

echo 

implying the script value hasn't been assigned to the variable.

Upvotes: 3

Views: 222

Answers (1)

pmod
pmod

Reputation: 11007

I guess you should use $(shell ...) function to initialize month variable:

month :=     $(shell $(R_HOME)/bin/Rscript ./R/reportperiod.R)

Upvotes: 3

Related Questions