Assigning output to an RScript variable for a makefile

I am trying to automate some R parsing using a makefile. Analysis is a monthly data analysis and report. It works so far, but to extend it I would like the default action to be to generate the current report, but the month can be specified if needed.

I am having trouble assigning the default report period (calculated by 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

required (lubridate)

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

      

but this just displays

echo 

      

implies that no script value has been assigned to a variable.

+3


source to share


1 answer


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



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

      

+3


source







All Articles