В Fri, 17 Nov 2023 12:19:21 +0200 Christiaan Pieterse <pietie.cjp.1...@gmail.com> пишет:
> #' # Set the working directory to a temporary directory > #' setwd(tempdir()) > #' # Clean up the temporary directory > #' unlink(temp_dir, recursive = TRUE) This code looks like it shouldn't be working as written. I don't see the variable temp_dir being defined anywhere, so it should have failed with Error: object 'temp_dir' not found. Have you run roxygenise() in order to generate the man/*.Rd files (which is what R cares about)? It's best to avoid changing the global state of the application, including the current directory. When you have to setwd(), do it the following way: oldwd. <- setwd(...) # do the thing setwd(oldwd.) In my opinion, it's better to provide an argument for your function to let the user specify the destination file. This would let the user say IOPS(outfile = 'Combined_Results_2.xlsx') without overwriting the Combined_Results.xlsx that already exists or even outfile = file.path(tempdir(), 'whatever.xlsx') to put the file into another directory. I think you will also need to remove that file at the end of your example. (Cleaning the whole tempdir(), on the other hand, could be bad for the user.) > * checking examples ... [26s] NOTE > Examples with CPU (user + system) or elapsed time > 5s > user system elapsed > IOPS 15.23 2.89 22.41 22 seconds is much better! How much time is spent in read.csv(system.file("extdata", "ExampleTradeData.csv", package = "iopspackage"))? Can you resave it under data/*.rda, load it using data() and save some time there? If you cannot squeeze your data even further, it may help to profile the example(IOPS) run [1] and try to find faster alternatives for the parts of the code that take the most time. It's not exactly trivial (make sure to read both WRE 3.2 and help(Rprof)), but it should be possible to improve your time. -- Best regards, Ivan [1] https://cran.r-project.org/doc/manuals/R-exts.html#Profiling-R-code-for-speed ______________________________________________ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel