Storing an XLConnect workbook object as data in an R package results in: Error: NullPointerException (Java). -
i'm creating first r package in order colleagues perform series of relatively involved data processing tasks. have lot of r functions data cleaning analysis, trying add things streamline workflow increase speed , reduce error.
one of steps users have perform create specific series of directories , sub-directories in different files stored later on. next, have excel workbook template needs inserted specific folders. currently, can create directories r code users have copy excel template correct places manually. wish automatically r function because i've observed easy make errors if step done manually--copying template wrong directory, using wrong version of template in wrong place, etc.
of note, excel workbook template trying regenerate r function pretty complicated. contains small amount of data , bunch of formatting , hidden formulae. workbook template has stay way legacy reasons. due it's complexity, i'm not sure can create template de novo r functions put in base data, set formatting, , set complex formula rules without introducing errors.
my approach far has been use:
mywb<-xlconnect::loadworkbook("c:/my docs/template.xlsx")
in order create xlconnect "workbook" object copy of excel template have stored locally on machine.
if use str()
examine newly created workbook object, see:
formal class 'workbook' [package "xlconnect"] 2 slots ..@ filename: chr "c:/my docs/template.xlsx" ..@ jobj :formal class 'jobjref' [package "rjava"] 2 slots .. .. ..@ jobj :<externalptr> .. .. ..@ jclass: chr "com/miraisolutions/xlconnect/integration/r/rworkbookwrapper"
this works great reproducing copies of .xlsx template while working interactively in same r session. can use:
xlconnect::saveworkbook(myworkbook,file="c:/some new folder/new copy of template.xlsx")
i can go "some new folder" , sure enough, "new copy of template.xlsx" functional copy of original template, in new folder.
the problem want excel template workbook live inside package type of object r can use re-create workbook on machine of has installed package, without them having obtain copy of excel file, store somewhere, move around, etc. tried, therefore using devtools::use_data(mywb)
in order store mywb object data in package's data folder .rda file (i have tried function internal set false in order store mywb in r/ sysdata.rda).
i build package lazydata: true
in description file. want use xlconnect::saveworkbook(mywb,"c:/new folder/copy of template.xlsx")
make copy of template in correct directory package use. functions in package can see mywb object, know was, in fact, lazily loaded, , when examine str(mywb)
appears intact:
formal class 'workbook' [package "xlconnect"] 2 slots ..@ filename: chr "c:/my docs/template.xlsx" ..@ jobj :formal class 'jobjref' [package "rjava"] 2 slots .. .. ..@ jobj :<externalptr> .. .. ..@ jclass: chr "com/miraisolutions/xlconnect/integration/r/rworkbookwrapper"
when run xlconnect::saveworkbook(mywb,"c:/new folder/copy of template.xlsx")`, however, following error:
error: nullpointerexception (java):
i know nothing java, guess mywb object created xlconnect java object , i'm losing (a pointer?) when save object data in r package.
what try next?
thank you.
p.s. pretty new stack overflow , trying learn how ask question. struggled creating reproducible example question since require create new r package , have copy of excel template on hand. luckily seems error independent of specifics of template. hope did reasonable job of explaining situation , have tried, i'd appreciate feedback on creating better question.
Comments
Post a Comment