Q:

unable to write the ouput of an object to file in R

I have an R script that does bunch of stuff and at the end of the script run, I like to write the final output to file. The final object call p contains the data like this:
dput(p)
"[{\"name\":\"loess\",\"data\":[[1373241600000,3.49571041760408],[1373241660000,3.4844505982485],[1373241720000,3.47324293684199],[1373241780000,3.46208745646435],[1373241840000,3.45098418019539],[1373241900000,3.43993313111491],[1373241960000,3.42893433230273],[1373242020000,3.41798780683864],[1373242080000,3.40709357780246],[1373242140000,3.39625166827399],[1373242200000,3.38546210133304],[1373242260000,3.37472490005941],[1373242320000,3.36404008753291],[1373242380000,3.35340768683334],[1373242440000,3.34282772104051],[1373242500000,3.33230021323422],[1373242560000,3.32182518649429],[1373242620000,3.31140266390052],[1373242680000,3.30103266853271],[1373242740000,3.29071522347067],[1373242800000,3.28045035179421],[1373242860000,3.27023807658312],[1373242920000,3.26007842091723],[1373242980000,3.24997140787633],[1373243040000,3.23991706054023],[1373243100000,3.22991540198874],[1373243160000,3.21996645530166],[1373243220000,3.2100702435588],[1373243280000,3.20022678983996],[1373243340000,3.19043611722495],[1373243400000,3.18069824879358],[1373243460000,3.17101320762565],[1373243520000,3.16138101680096],[1373243580000,3.15180169939934],[1373243640000,3.14227527850057],[1373243700000,3.13280177718446],[1373243760000,3.12338121853083],[1373243820000,3.11401362561948],[1373243880000,3.10469902153021],[1373243940000,3.09543742934283],[1373244000000,3.08622887213715],[1373244060000,3.07707337299297],[1373244120000,3.0679709549901],[1373244180000,3.05892164120834],[1373244240000,3.0499254547275],[1373244300000,3.04098241862739],[1373244360000,3.03209255598781],[1373244420000,3.02325588988857],[1373244480000,3.01447244340947],[1373244540000,3.00574223963032],[1373244600000,2.99706530163093],[1373244660000,2.9884416524911],[1373244720000,2.97987131529064],[1373244780000,2.97135431310935],[1373244840000,2.96289066902704],[1373244900000,2.95448040612352],[1373244960000,2.94612354747859],[1373245020000,2.93782011617205],[1373245080000,2.92957013528372],[1373245140000,2.92137362789341],[1373245200000,2.9132306170809],[1373245260000,2.90514112592602],[1373245320000,2.89710517750857],[1373245380000,2.88912279490835],[1373245440000,2.88119400120517],[1373245500000,2.87331881947884],[1373245560000,2.86549727280916],[1373245620000,2.85772938427594],[1373245680000,2.85001517695898],[1373245740000,2.84235467393809],[1373245800000,2.83474789829308],[1373245860000,2.82719487310374],[1373245920000,2.8196956214499],[1373245980000,2.81225016641135],[1373246040000,2.8048585310679],[1373246100000,2.79752073849936],[1373246160000,2.79023681178553],[1373246220000,2.78300677400622],[1373246280000,2.77583064824123],[1373246340000,2.76870845757037],[1373246400000,2.76164022507344],[1373246460000,2.75462597383026],[1373246520000,2.74766572692063],[1373246580000,2.74075950742435],[1373246640000,2.73390733842123],[1373246700000,2.72710924299107],[1373246760000,2.72036524421369],[1373246820000,2.71367536516889],[1373246880000,2.70703962893647],[1373246940000,2.70045805859624],[1373247000000,2.693930677228],[1373247060000,2.68745750791157],[1373247120000,2.68103857372674],[1373247180000,2.67467389775333],[1373247240000,2.66836350307114],[1373247300000,2.66210741275998],[1373247360000,2.65590564989964],[1373247420000,2.64975823756995],[1373247480000,2.6436651988507],[1373247540000,2.63762655682169],[1373247600000,2.63164233456275],[1373247660000,2.62571255515366],[1373247720000,2.61983724167425],[1373247780000,2.61401641720431],[1373247840000,2.60825010482364],[1373247900000,2.60253832761207],[1373247960000,2.59688110864938],[1373248020000,2.5912784710154],[1373248080000,2.58573043778991],[1373248140000,2.58023703205274],[1373248200000,2.57479827688368],[1373248260000,2.56941419536255],[1373248320000,2.56408481056914],[1373248380000,2.55881014558327],[1373248440000,2.55359022348473],[1373248500000,2.54842506735335],[1373248560000,2.54331470026891],[1373248620000,2.53825914531123],[1373248680000,2.53325842556012],[1373248740000,2.52831256409537],[1373248800000,2.5234215839968],[1373248860000,2.51858550834422],[1373248920000,2.51380436021742],[1373248980000,2.50907816269621],[1373249040000,2.50440693886041],[1373249100000,2.49979317477766],[1373249160000,2.49523927109528],[1373249220000,2.49074512276254],[1373249280000,2.48631062472871],[1373249340000,2.48193567194306],[1373249400000,2.47762015935487]]}]"

I tried:
sink("output.txt")
cat(p)
sink()

did not work
I tried(
writeLines(p, "output.txt")

did not work
I tried
accepted  fileConn<-file("output.txt")
writeLines(p, fileConn)
close(fileConn) 

it did not work.
When I execute any of these commands right from the R console it works. But I need this to work with the R script since I will run this script on an scheduled basis. Any ideas what I might be missing here?

A:

If the commands work from console but not from the script its most likely a function of write permissions and/or wrong path (as mentioned by others). Within my scripts I always provide full path. I build a hierarchy to keep track of things:
basedir = "C:/Users/Rdas01/Documents/FTPHome"
inputdir = file.path(basedir,"Input")
outdir = file.path(basedir,"Output")
reportdir = file.path(basedir,"Report")

f_Rdata = file.path(outdir,"Data.Rdata")
f_out = file.path(outdir,"output.txt")

# Do your calculations here

write.csv(p,file = f_out, row.names=F)
save.image(file = f_Rdata)
print(f_out)
print(f_Rdata)

