haven::write_xpt question

Hi everybody,

I want to create a SAS xpt file with the function haven::write_xpt. Could somebody show me how to create the file in a directory different than the current working directory?
Thank you very much.

Ha

library(haven)  # Version 2.4.1
#> Warning: package 'haven' was built under R version 4.0.5

R.version
#>                _                           
#> platform       x86_64-w64-mingw32          
#> arch           x86_64                      
#> os             mingw32                     
#> system         x86_64, mingw32             
#> status                                     
#> major          4                           
#> minor          0.4                         
#> year           2021                        
#> month          02                          
#> day            15                          
#> svn rev        80002                       
#> language       R                           
#> version.string R version 4.0.4 (2021-02-15)
#> nickname       Lost Library Book

# OK if creating the xpt file in current working directory
haven::write_xpt(mtcars, 'mtcars.xpt')

# This command will give an error 
haven::write_xpt(mtcars, 'c:/downloads/mtcars.xpt')
#> Error: Failed to open 'c:\downloads\mtcars.xpt' for writing

Created on 2021-06-29 by the reprex package (v2.0.0)

This works for me, I guess the reason is the provided path does not exist (i.e.there is no folder called 'downloads' under your C drive, the path of Windows default Downloads is something likeļ¼šC:/Users/xxx/Downloads)

You are right; thank you very much.

Best.

Ha

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.